Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2012
    Rep Power

    Default 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.

    Java 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(;
    		String givenname;
    		int[] choosenumb = new int[2];
    		System.out.println("\tDerek's Lottery Game");
    		System.out.println("What is your given name?");
    		givenname =;
    		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!");

  2. #2
    Eleeist is offline Member
    Join Date
    May 2011
    Rep Power

    Default 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.

Similar Threads

  1. Creating 2D array from all user input
    By peek_a_boo in forum New To Java
    Replies: 1
    Last Post: 12-08-2011, 08:16 PM
  2. Print Parts Of An Array [User Input]
    By PrimalScientist in forum New To Java
    Replies: 22
    Last Post: 08-30-2011, 11:09 AM
  3. trouble converting unsigned int to byte array
    By zsefv in forum New To Java
    Replies: 9
    Last Post: 05-06-2011, 09:17 AM
  4. user input array
    By localhost in forum New To Java
    Replies: 5
    Last Post: 12-30-2010, 04:00 AM
  5. Read user input into integer array
    By varunb in forum New To Java
    Replies: 12
    Last Post: 07-09-2010, 12:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts