Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* CREATED BY AGENTTADPOLE.
- 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
- 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]).
- You may not use this work for any commercial purposes.
- 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 :)
- */
- import java.util.Random;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- // Defining variables and such
- Scanner scanner = new Scanner(System.in);
- Random rand = new Random();
- int[] numbers;
- numbers = new int[10];
- String output = "";
- // Generating random numbers
- for(int i=0;i<10;i++) {
- numbers[i] = rand.nextInt(10) + 1;
- }
- // Quizzing user on random numbers
- System.out.println("To play this game, guess 10 randomised numbers between 1 and 10.");
- for(int i=0;i<10;i++) {
- int answer;
- int qNumber = i+1;
- do {
- System.out.print("Question " + qNumber + ": ");
- answer = scanner.nextInt();
- if(answer != numbers[i]) {
- System.out.println("Incorrect answer");
- }
- }
- while(answer != numbers[i]);
- }
- scanner.close();
- System.out.println("");
- //Printing visual graph and numbers
- output = "These were the random numbers: ";
- for(int i = 0;i<numbers.length;i++) {
- output = output + numbers[i] + " ";
- }
- System.out.println(output);
- System.out.println("Here is a visual representation of the random numbers");
- for(int i=0;i<10;i++) {
- output = "";
- int qNumber = i+1;
- for(int j=0;j<numbers[i];j++) {
- output = output + "*";
- }
- //If statement not necessary, just makes the graph more aligned
- if(qNumber == 10) {
- System.out.println(qNumber + ": " + output);
- } else {
- System.out.println(" " + qNumber + ": " + output);
- }
- }
- System.exit(0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment