Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

[Java] Need help real quick

Hey guys, I'm really new to Java and I'm trying to write a short program that inputs the names and ages of people until the age reaches 100. I know you'd need a 'while' statement, but I'm not sure how to configure it.

Also, this is optional, but how would I print 10 random integers between 1 and 10 inclusive?

For the age thing: Meh?
Code:
import java.util.Scanner;

 

class ghhjghjgj{

    static void main(String [] args){

          Scanner reader = new Scanner(System.in);

          int age;

          

          age = reader.nextInt();

          while (age <= 100){

               System.out.print(age);

               age++;

          }

    }

}

 
 
I'm not working with Java so I cannot help you very well.

What's the problem with your code? Did you try printing the age variable before the loop starts?

For the random int, try java.lang.Math.random():
Returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0.
 
I'm not 100% sure what you're exactly trying to do. I'm guessing you're trying to read input 100 times from either the console or a file and display it. The first step would be to actually read the input during the while loop. This means that every iteration of the loop, something is being read in. Then you can do what you want with that information (like printing it) after that.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top