-
November 21st, 2008, 10:22 AM
#1
Another program with arrays
Hey all, thanks for your help with my last program, I now have to write another program to take in two sets of integers and store them, and then print them out along the lines of "Data for array 1 is: 2 5 4 6" and the same for array 2.
Here is my code so far:
Code:
///////////////////////////////////////////////////
/////
///// LogName: pxd08u
///// FullName:
///// CreationDate: 2008-11-19 12:51:09
/////
///////////////////////////////////////////////////
import java.io.*;
// Integer Array Calculations
public class union {
// put your global declarations here
// put any helper methods here
public static void main(String[] argv) {
// put your local declarations here
int firstArray [] = new int [100];
int secArray [] = new int [100];
int firstInt = 0;
int secInt = 0;
// prompt and read
for (int counter = 0; counter < 100; counter++) {
System.out.println ("Enter data for array 1 (0 to finish): ");
firstInt = UserInput.readInt;
if (firstInt == 0) {
break;
}
for (int a1 = 0; a1 < firstArray.length; a1 ++) {
if firstArray [a1] = firstInt {
break;
}
}
for (int x = 0; x < firstArray.length; x++) {
firstArray [x] = firstInt;
}
System.out.println ("Enter data for array 2 (0 to finish): ");
secInt = UserInput.readInt;
if (secInt == 0) {
break;
}
for (int a2 = 0; a2 < secArray.length; a2 ++) {
if secArray [a1] = secInt {
break;
}
}
for (int z = 0; z < secArray.length; z++) {
secArray [z] = secInt;
}
}
// compute and print
for (int a3 = 0; a3 < firstArray.length; a3++) {
System.out.println ("Data for array 1 is: " + firstArray [a3]);
}
for (int a4 = 0; a4 < secArray.length; a4++) {
System.out.println ("Data for array 2 is: " + secArray [a4]);
}
} // end of main
} // end class
I'm getting "( expected" in line 42, "illegal start of expression" on line 46, the same errors in lines 62 and 67 respectively, and ") expected" on line 66. I need to make sure there are no duplicate integers, and quit if a zero is entered. I realise my code is probably littered full of stupid mistakes, as you can see I'm still VERY much still learning, any help is as always greatfully recieved.
-
November 21st, 2008, 11:59 AM
#2
Re: Another program with arrays
We are not a debugging service. The compiler has told you which line has a problem and what the problem is, so look at each line that has a problem and work out what is wrong. Hint: fix the first error and recompile as sometimes the next error will be fixed by sorting the preceding problem.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|