Results 1 to 4 of 4
  1. #1
    brmcdani is offline Member
    Join Date
    Feb 2010
    Posts
    5
    Rep Power
    0

    Default Inserting input into array

    I am trying to figure out how to input user entries into an array. Here is what I have so far and I am trying to figure out my next step. Any help would be apprecitated.

    Java Code:
    import java.util.Scanner;
    
    public class partOne {
    	
    	public static void main(String[] args) {
    		Scanner input = new Scanner(System.in);
    		int numbOne;
    
    		System.out.print("Please type a number or enter end to calculate lowest number: ");
    		numbOne = input.nextInt();
    
    		
    	}
    }

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    I am trying to figure out my next step.

    Step 0: Change the name of the class to PartOne

    Step 1: Declare an array variable and initialise it.

    Details at Arrays (The Java™ Tutorials > Learning the Java Language > Language Basics)

  3. #3
    [RaIdEn] is offline Senior Member
    Join Date
    Oct 2009
    Location
    California,US
    Posts
    201
    Rep Power
    6

    Default

    Quote Originally Posted by brmcdani View Post

    Java Code:
    import java.util.Scanner;
    
    public class partOne {
    	
    	public static void main(String[] args) {
    		Scanner input = new Scanner(System.in);
    		int numbOne;
    
    		System.out.print("Please type a number or enter end to calculate lowest number: ");
    		numbOne = input.nextInt();
    
    		
    	}
    }
    actually theres a problem with your current code.you said in the print statement to type in a number or "end". while scanning for a number.

  4. #4
    FlyNn is offline Senior Member
    Join Date
    Feb 2010
    Posts
    128
    Rep Power
    0

    Default

    import java.util.Scanner;

    //Start class names with capital
    public class PartOne {

    public static void main(String[] args) {

    //Define array of type int(beacause you want to enter digits)
    int[] myArray = new int[5];

    //Define input
    Scanner input = new Scanner(System.in);
    int numbOne=0;



    //This loop will allows you to enter 5 digits.
    for(int i =0:i<myArray.length;i++)
    {
    System.out.print("Please type a number or enter end to calculate lowest number: ");
    numbOne = input.nextInt();
    myArray[i]=numberOne;
    }

    }
    }

    I havent compiled it just wrote in the browser. Should be working thought. Hope this helps. If you want more help just PM me :)
    Good luck :)

    P.S. The "end" bit would not work. To make it work you would have to use a different type of loop which would say while the entered digit is not a 0(for example) ask the user for a digit,So in other words if you have entered a 0 then do System.exit(0); However you could just use a simple if statement to check if digit entered is == to 0;
    Last edited by FlyNn; 02-05-2010 at 03:37 PM.

Similar Threads

  1. New to java, need a little help with array input
    By black06vfr in forum New To Java
    Replies: 11
    Last Post: 04-29-2009, 06:46 PM
  2. Array Input
    By Rose88 in forum New To Java
    Replies: 2
    Last Post: 04-19-2009, 11:39 PM
  3. Replies: 0
    Last Post: 04-14-2008, 09:39 PM
  4. input placed in array
    By smilejava in forum New To Java
    Replies: 5
    Last Post: 11-12-2007, 08:29 AM
  5. input placed in array
    By smilejava in forum New To Java
    Replies: 1
    Last Post: 11-05-2007, 01:32 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
  •