| | |
Java help - RE Arrays
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Nov 2007
Posts: 12
Reputation:
Solved Threads: 1
Hi, I am having some trouble with arrays.
I have an array of 5 elements. The values of the array are integers. I want to validate the input using an if statement. (the numbers must be between 10 and 100).
I then want to compare the user input to the unique numbers in the array using a for statement. I only want to store the new number if it is unique.
Please help, I'm desperate!!
I have an array of 5 elements. The values of the array are integers. I want to validate the input using an if statement. (the numbers must be between 10 and 100).
I then want to compare the user input to the unique numbers in the array using a for statement. I only want to store the new number if it is unique.
Please help, I'm desperate!!
•
•
Join Date: Aug 2008
Posts: 1,162
Reputation:
Solved Threads: 138
show us your effort with some code and we will help
Custom Application & Software Development
www.houseshark.net
www.houseshark.net
•
•
Join Date: Nov 2007
Posts: 12
Reputation:
Solved Threads: 1
This is the code so far
public class array
{
//This gerts 5 unique numbers from the user
public void getNumbers()
{
Scanner input = new Scanner( System.in );
new int[5] //Constructing the array
int[] number = new int[5]; //Declaration of the array variable
int count = 0; // Number of uniques read
int entered = 0; // Number of numbers entered
//Checks whether the number entered has already been entered into the array, if it has then the following message is displayed:
while( entered < numbers.length )
{
System.out.print( "Enter number:" );
int[0] = input.nextInt;
if (int[] == number)
public class array
{
//This gerts 5 unique numbers from the user
public void getNumbers()
{
Scanner input = new Scanner( System.in );
new int[5] //Constructing the array
int[] number = new int[5]; //Declaration of the array variable
int count = 0; // Number of uniques read
int entered = 0; // Number of numbers entered
//Checks whether the number entered has already been entered into the array, if it has then the following message is displayed:
while( entered < numbers.length )
{
System.out.print( "Enter number:" );
int[0] = input.nextInt;
if (int[] == number)
I'll go through each of the errors I see.
1)
This line does nothing useful and is missing a semicolon. You should remove the line completely.
2)
This line should be using the variable name, not the variable type to reference the array. Also, you're missing parentheses after
3)
I have no idea what you're trying to do here.
1)
new int[5] //Constructing the array This line does nothing useful and is missing a semicolon. You should remove the line completely.
2)
int[0] = input.nextInt This line should be using the variable name, not the variable type to reference the array. Also, you're missing parentheses after
nextInt , also, you want to change the index each loop so you don't rewrite over element 0. Probably should be: number[entered] = input.nextInt(); 3)
if (int[] == number) I have no idea what you're trying to do here.
Last edited by destin; Nov 9th, 2008 at 10:20 pm.
![]() |
Similar Threads
- arrays in java!!! (Java)
- Java Multidimensional Arrays (Java)
- java problem with creating arrays (Java)
- Having trouble with comparing strings and arrays (Java)
- build java game (Java)
- Class Passing and Returning Arrays (Java)
- New to Java (Java)
Other Threads in the Java Forum
- Previous Thread: calculating three dice
- Next Thread: Help adding Intergers in array(s)
Views: 450 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for Java
android api apple applet application arguments array arrays automation bidirectional binary birt bluetooth calculator chat class classes client code columns component database designadrawingapplicationusingjavajslider detection draw eclipse editor error errors event exception expand file fractal game givemetehcodez graphics gui guidancer helpwithhomework html ide image inetaddress input integer intellij j2me java javamicroeditionuseofmotionsensor javaprojects jme jmf jni jpanel julia linux list loop map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie number object oracle os plazmic print problem program programming project recursion scanner screen server set signing size smart sms smsspam socket sort sql string subclass support swing test threads time transfer tree windows






