Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ch7ex8;
- import java.util.Scanner;
- import java.util.Random;
- public class Ch7Ex8
- {
- public static void main(String[] args)
- {
- Scanner sc=new Scanner(System.in);
- Random generator = new Random();
- int rand, score=1000, guessCount=0;
- System.out.println("High Low Game\n\nRules:\nNumbers 1 to 6 are low.\nNumbers 8 to 13 are high.");
- System.out.println("Number 7 is neither high nor low.\n\nYou start with 1000 points.\n");
- for(int c=0;score>0;c++)
- {
- guessCount++;
- System.out.println("Current Score: "+score);
- System.out.print("Enter points to risk: ");
- int risk=sc.nextInt();
- while(risk>score)
- {
- System.out.println("Insufficient points!\nEnter a new risk: ");
- risk=sc.nextInt();
- }
- rand=generator.nextInt(13)+1;
- System.out.print("Predict High (1) or Low (0): ");
- int guess=sc.nextInt();
- System.out.println("The number was: "+rand);
- if((guess==0&&rand<7)||(guess==1&&rand>7))
- {
- score+=risk;
- System.out.println("You gain "+risk+" points!");
- }
- else
- {
- score-=risk;
- System.out.println("You lose "+risk+" points!");
- }
- }
- System.out.println("Your score has reached 0!\nTotal guesses: "+guessCount+"\nThanks for playing!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment