Created
June 8, 2021 13:44
-
-
Save CaptainHandyman/4ce290af872ec7687fd2b6bb191517c3 to your computer and use it in GitHub Desktop.
A game written in Java where you have to hit a number.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.redbull4.helloworld; | |
import java.util.Scanner; | |
public class Hello { | |
static Scanner sc = new Scanner(System.in); | |
public static int getRandomNumber(final int a, final int b) { | |
double output = Math.random() * ((b - a - 1) + a); | |
return (int) output; | |
} | |
public static void main(String[] args) { | |
while (true) { | |
System.out.print("Suit a number from 1 to 10: "); | |
if (sc.nextInt() == getRandomNumber(1, 10)) { | |
System.out.println("That's right, you hit the number!"); | |
break; | |
} else | |
System.out.println("Wrong, try again!"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment