can someone tell me whats wrong in this program /****************************************************************************** Welcome to GDB Online. GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl, C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog. Code, Compile, Run and Debug online from anywhere in world. *******************************************************************************/ public class Main { public static void main(String[] args){ System.out.println("Hey Guys welcome back to my guessing number game."); System.out.println("Pick a number: "); int maxnumber; int RandomNumber; maxnumber = In.getInt(); RandomNumber = (int)(Math.random()*999 + 1); System.out.println("RandomNumber" + RandomNumber + maxnumber);// remove RandomNumber and maxnumber at the end int number; int tries = 0; int guess; boolean win = false; while (win == false){ System.out.println("Guess a number between 1 and "+ maxnumber +": "); guess = In.getInt(); tries++; if (guess == number){ win = true; } else if(guess < number){ System.out.println("the number you guess is smaller than the secret number. Please try again"); } else if(guess > number){ System.out.println("the number you guess is smaller than the secret number. Please try again"); } } System.out.println("Congratulation You win!"); System.out.println("It took you " + tries + " tries."); } }
your positioning of parenthesis
You're not reading user input correctly.
If you're meaning to use the scanner class you need to import it and call the method under the class
this line -> maxnumber = In.getInt();
I have no clue what code you are trying to run this in, but I pasted the code into GDB and it will display your errors at the bottom
The language is java and you're trying to run c code @0mega
my teacher told me that dont use scanner
alright then these are your errors
what did your teacher tell you to use?
in.getInt();
sheesh no need to be rude
but my teacher told me not to use it
Did your teacher provide you a method to handle user input? You can't just call a function and expect it to work without importing it. If you know the name of the function and the package it's supposed to come from I can tell you what the correct syntax is.
There's one more option. Maybe your teacher wants you to use Console.readline() and parse the string as an int? See something like https://www.tutorialspoint.com/java/io/console_readline.htm . You should clarify if you can with your teacher. There aren't that many ways to read user input in java, (or any command line program to be honest. They all use standard system i/o streams after all.)
I believe you have to make a scanner
but my teacher told me not to use scanner don't know why
How else would you get user input without a scanner?
Also in isn't declared..
In.getint?
I gave the asker 2 other ways to get user input without scanner.
Seems like you're trying to use a scanner.
Seems like you either have to declare variables or use a scanner.
Not sure how you could get input without a scanner... to scan the line of the input
Pretty sure declaring a scanner would be "Scanner scan = new Scanner();
Then you'd use scan.nextInt();
I believe.
Haven't coding in awhile forgot the syntax.
Join our real-time social learning platform and learn together with your friends!