Results 1 to 4 of 4
Thread: Inserting input into array
- 02-05-2010, 03:01 AM #1
Member
- Join Date
- Feb 2010
- Posts
- 5
- Rep Power
- 0
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(); } }
- 02-05-2010, 03:23 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
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)
- 02-05-2010, 03:46 AM #3
Senior Member
- Join Date
- Oct 2009
- Location
- California,US
- Posts
- 201
- Rep Power
- 4
- 02-05-2010, 02:33 PM #4
Senior Member
- Join Date
- Feb 2010
- Posts
- 128
- Rep Power
- 0
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 02:37 PM.
Similar Threads
-
New to java, need a little help with array input
By black06vfr in forum New To JavaReplies: 11Last Post: 04-29-2009, 05:46 PM -
Array Input
By Rose88 in forum New To JavaReplies: 2Last Post: 04-19-2009, 10:39 PM -
Sorting, Searching, and Inserting into a sorted array
By Java Tip in forum java.langReplies: 0Last Post: 04-14-2008, 08:39 PM -
input placed in array
By smilejava in forum New To JavaReplies: 5Last Post: 11-12-2007, 07:29 AM -
input placed in array
By smilejava in forum New To JavaReplies: 1Last Post: 11-05-2007, 12:32 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks