and im trying to create a simple array table in ecplise. 3 columns with 3 lines. 1st and 2nd columns are strings and 3rd column is doubles. i also want the user to have an option to rewrite the current line if he made a mistake.
very simple right? i'm getting an error that i do not understand. can someone please explain it to me? here is the code:
import java.util.Scanner;
public class exercise923
{
public static void main(String args[])
{
int counter = 0, check; //these are numbers used for the loops
String column1[] = new String[3]; //these are data for the table
String column2[] = new String[3];
double column3[] = new double[3];
Scanner Scan = new Scanner(System.in);
//this do while loop allows the user to enter data for the table
do {
System.out.println("type values for columns 1, 2, and 3 of line: " + counter);
column1[counter] = Scan.nextLine();
column2[counter] = Scan.nextLine();
column3[counter] = Scan.nextDouble();
//after typing out the data for this line, user can type 1 to go to the next line, or 2 to rewrite this line
System.out.println("type 1 to continue, 2 to rewrite");
check = Scan.nextInt();
if (check==1) {
counter++;
}
} while (counter<3);
//once user is finished typing out all the data for the 3 lines
//of 3 columns, the table gets printed out.
counter=0;
System.out.println("your finished table:");
do {
System.out.print(column1[counter] + "\t");
System.out.print(column2[counter] + "\t");
System.out.println(column3[counter]);
counter++;
} while (counter<3);
} // main
} // class
when i run this, i get:
type values for columns 1, 2, and 3 of line: 0
jack
bob
3
type 1 to continue, 2 to rewrite
2
type values for columns 1, 2, and 3 of line: 0
dale
sally
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextDouble(Unknown Source)
at exercise923.main(exercise923.java:21)