import java.io.File; import java.util.*; import java.io.FileNotFoundException; i
ID: 3875242 • Letter: I
Question
import java.io.File;
import java.util.*;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.util.Scanner;
public class Assign_2{
public static void main(String[] theArgs){
Scanner input = null;
PrintStream output = null;
String inFileName = "in2a.txt";
String outFileName = "out.txt";
boolean filesOk = false;
try{
input = new Scanner (new File(inFileName));
output = new PrintStream (new File (outFileName));
}
catch (FileNotFoundException e) {
System.out.println ("Can't open file - " + e);
}
if (filesOk){
public static int Array (int input){
int [][] Array1 = int A (input);
System.out.print(Array1);
}
}
}
}
Question Why cant i Input array here from the file it always has error .
Assign_2.java:23: error: illegal start of expression
public static int Array (int input){
^
Assign_2.java:25: error: '.class' expected
int [][] Array1 = int A (input);
^
Assign_2.java:30: error: class, interface, or enum expected
}
^
3 errors
Just say inside the txt has these numbers
1 2 3 4 5
6 7 8 9 9
How do i make the first line into array variable
Explanation / Answer
/* A line of numbers can't be input in one go as an array.Either you have to read it one by one or you can read it as a line and then separate them as numbers. Following is the
code to read that line and put it in the array.In case we know the data in the file*/
int[][] Arr = new int[2][5];
for (int i = 0; i<2; i++){ // reading two rows
for (int j = 0; j<5; j++){ // reading five numbers
Arr[i][j] = input.nextInt(); //input is as defined in the program
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.