0

JAVA HELP

Pls I need help to create a Java code that allows user guess a number and compares the number with a guessed number. If the number input by the user is between 2 and 8, ask user "do you want to find factorial?" If yes, code implements factorial of input number. Pls who can help? This is what I have: public static void main(String args[]) { Scanner keyboard = new Scanner(System.in); int count = 0; int a = 1 + (int) (Math.random() * 99); int guess = 0; System.out.println("I am thinking of a number from 1 to 100" + " ... guess what it is ?"); while (guess != a) { guess = keyboard.nextInt(); count++; if (guess > a) { System.out.println("lower!"); } else if (guess < a) { System.out.println("higher!"); } } System.out.println("Congratulations. You guessed the number with " + count + " tries!"); }

5th Jun 2019, 12:06 AM
Onuedem Eberechukwu
Onuedem Eberechukwu - avatar
4 Réponses
+ 2
your code is ok, but if it is whole code you need import and class name: import java.util.Scanner; class Example { // here is your code : main() // ... }
5th Jun 2019, 1:18 AM
zemiak
+ 1
You should post the link of your code not the code itself. Have you tried it? On sololearn it will not work because you have to input all at the beginning. But using an IDE on your PC it should work.
5th Jun 2019, 1:06 AM
Denise Roßberg
Denise Roßberg - avatar
0
An idea just came to me and I will like to include it in this code. If the number input by the user is between 2 and 8, ask user "do you want to find factorial?" If yes, code implements factorial of input number. Pls who can help?
5th Jun 2019, 2:34 AM
Onuedem Eberechukwu
Onuedem Eberechukwu - avatar