AgentTadpole

Answers - Random Number Quiz

Oct 21st, 2013
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.18 KB | None | 0 0
  1. /* CREATED BY AGENTTADPOLE.
  2. This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License, which can be viewed in full here - http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_US
  3. You have permission to modify this program and release the modification to the public, under the condition that you use the same or similar license I do and you provide attribution to me, AgentTadpole ([email protected]).
  4. You may not use this work for any commercial purposes.
  5. If you use this for anything or modify it and upload it, I'd appreciate you letting me know via the email above so I can see what you did :)
  6. */
  7.  
  8. import java.util.Random;
  9. import java.util.Scanner;
  10.  
  11. public class Main {
  12.     public static void main(String[] args) {
  13.         // Defining variables and such
  14.         Scanner scanner = new Scanner(System.in);
  15.         Random rand = new Random();
  16.        
  17.         int[] numbers;
  18.         numbers = new int[10];
  19.        
  20.         String output = "";
  21.        
  22.         // Generating random numbers
  23.         for(int i=0;i<10;i++) {
  24.             numbers[i] = rand.nextInt(10) + 1;
  25.         }
  26.        
  27.         // Quizzing user on random numbers
  28.         System.out.println("To play this game, guess 10 randomised numbers between 1 and 10.");
  29.         for(int i=0;i<10;i++) {
  30.             int answer;
  31.             int qNumber = i+1;
  32.             do {
  33.                 System.out.print("Question " + qNumber + ": ");
  34.                 answer = scanner.nextInt();
  35.                 if(answer != numbers[i]) {
  36.                     System.out.println("Incorrect answer");
  37.                 }
  38.             }
  39.             while(answer != numbers[i]);
  40.         }
  41.         scanner.close();
  42.         System.out.println("");
  43.        
  44.         //Printing visual graph and numbers
  45.         output = "These were the random numbers: ";
  46.         for(int i = 0;i<numbers.length;i++) {
  47.              output = output + numbers[i] + " ";
  48.         }
  49.         System.out.println(output);
  50.        
  51.         System.out.println("Here is a visual representation of the random numbers");
  52.         for(int i=0;i<10;i++) {
  53.             output = "";
  54.             int qNumber = i+1;
  55.            
  56.             for(int j=0;j<numbers[i];j++) {
  57.                 output = output + "*";
  58.             }
  59.            
  60.             //If statement not necessary, just makes the graph more aligned
  61.             if(qNumber == 10) {
  62.                 System.out.println(qNumber + ": " + output);
  63.             } else {
  64.                 System.out.println(" " + qNumber + ": " + output);
  65.             }
  66.         }
  67.        
  68.         System.exit(0);
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment