How do you do "randSeed()" and "readLine()" in java? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How do you do "randSeed()" and "readLine()" in java?

I am currently working on a new code, but can't figure out how to use "randSeed() and "readLine"! I only learnt the basics of Java, so can you guys please help me here is my (buggy) code ⬇️⬇️⬇️ https://code.sololearn.com/chvm2JdMe7YQ/?ref=app

25th May 2018, 12:53 AM
DengSXCreates
DengSXCreates - avatar
2 Answers
+ 2
Sorry dude, I'm tired from working all day. lol Here is an updated version of what I posted. Going to delete the other one, this will work out better for you. Hit me up if you have questions. https://code.sololearn.com/cOPtWDKRItn7/#java import java.util.*; public class Program { public static void main(String[] args) throws Exception { Random rand = new Random(); int maxRandNum = 100; int randomNumber = (rand.nextInt(maxRandNum) + 1); Scanner scnr = new Scanner(System.in); int input; try { System.out.print("Enter your number: "); input = scnr.nextInt(); System.out.println(input); } catch (InputMismatchException exception) { System.out.println(); System.out.println("Input a number between 1 and " + randomNumber + "."); return; } if(input <= 0 || input > maxRandNum){ System.out.println("Number out of range!"); System.out.println("Select between 1 and " + maxRandNum); return; } if (input > randomNumber) { System.out.println("Try lower"); } else if (input < randomNumber) { System.out.println("Try higher"); } else { System.out.println("You did it! Congratulations!"); // delay(50); Can't use on SL. Use wait() or sleep() tho System.out.println("Made by DengSXCreates"); } System.out.println("(Random number was " + randomNumber + ")"); } } ::: OUTPUT ::: Enter your number: 13 Try higher (Random number was 58) Enter your number: asd Error! Input a number. Enter your number: 250 Number out of range! Select between 1 and 100 Enter your number: 99 Try lower (Random number was 54) Enter your number: 0 Number out of range! Select between 1 and 100 Enter your number: 1 You did it! Congratulations!
25th May 2018, 1:33 AM
Fata1 Err0r
Fata1 Err0r - avatar
+ 1
thanks!
25th May 2018, 2:13 AM
DengSXCreates
DengSXCreates - avatar