Trouble! - Converting an User Input value to Array.
I'm trying to make an Array of 3 values to my user input, so something like - int Array[2] but i can't figure it out... this is what my code looks like so far, im doing a lottery game code but i just can't seem to figure it out.
Code:
import java.util.ArrayList;
import java.util.Scanner;
import java.util.Random;
public class Assingnment2B {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner mykeys = new Scanner(System.in);
String givenname;
int[] choosenumb = new int[2];
System.out.println("\tDerek's Lottery Game");
System.out.println("\t---------------------");
System.out.println("What is your given name?");
givenname = mykeys.next();
System.out.println("WELCOME " + givenname + "!!!!");
System.out.println("Enter a 3-digit number followed by the <Enter> key:");
System.out.println("(Any one of the digits can be zero, and digits can repeat) >>");
choosenumb = mykeys.nextInt();//User Input number
Random rNum = new Random();
int n1 = rNum.nextInt(10); // First digit in the lottery
int n2 = rNum.nextInt(10); // Second Digit in the Lottery
int n3 = rNum.nextInt(10); //Third Digit in the lottery
if (choosenumb == n1)
System.out.println("Congratulations " + givenname + " you have won $1,000,000 for guessing the correct digits in the correct order!");
}
}
Re: Trouble! - Converting an User Input value to Array.
First of all, if you want to insert 3 values into an array, then you need an array with 3 indexes, not 2.
Secondly, you can use a loop to iterate through indexes and assign your values to them.