Please the code is not working and I\'m really busy so can you correct it for me
ID: 3620157 • Letter: P
Question
Please the code is not working and I'm really busy so can you correct it for me? ThanksThe first two column has 12 rows and the last two column is 17.
Below are the data file input
-999999 0 -999999 0
1 2 0 1
1 3 1 6
1 4 2 8
1 5 3 9
2 7 4 10
5 12 4 11
6 14 5 13
8 17 6 15
8 18 7 16
9 22 8 19
999999 0 8 20
8 21
9 23
9 24
9 25
999999 0
import java.io.*;
import java.util.*;
public class Proj1Main
{
private static Scanner ins = new Scanner(System.in);
public static void main(String[] args)
{
String filename;
int maxNum = 20;
int[] intArray = new int[maxNum];
int[] bIntArray = new int[maxNum];
int[] aRanks = new int[maxNum];
int[] bRanks = new int[maxNum];
System.out.println("Enter the name of the input file: ");
filename = ins.next();
Scanner input = null;
try
{
input = new Scanner(new File(filename));
}
catch(FileNotFoundException FNFE)
{
System.err.printf("Could not find the input file %s ", filename);
System.exit(1);
}
String comment = input.nextLine(); // to go to next line in input
int index = 0,lena=0,lenb=0;
String emptyLine;
String inputstring;
while ((lena<=maxNum&&lenb <= maxNum) && input.hasNextLine())
{
inputstring=input.nextLine();
String[] inputs=inputstring.split(" ");
intArray[lena] = Integer.parseInt(inputs[0]); //assign all first sequence inputs into intArray array
aRanks[lena] = Integer.parseInt(inputs[1]); //assign all second sequence inputs into aRanks array
lena++;
if(inputs.length>2)
{
bIntArray[lenb] = Integer.parseInt(inputs[2]); //assign all third sequence inputs into bIntArray array
bRanks[lenb] = Integer.parseInt(inputs[3]); //assign all fourth sequence inputs into bRanks array
lenb++;
}
}
for(int k=0;k<lena;k++)
System.out.println(intArray[k]);
for(int k=0;k<lenb;k++)
System.out.println(bIntArray[k]);
//ranksByMerge();
}
}
Explanation / Answer
please rate - thanks the first line of input was being ignored because of the line of code that I commented out (in red) I also thought it wasn't working before and ignoring the first line until I saw that import java.io.*;import java.util.*;
public class Proj1Main
{
private static Scanner ins = new Scanner(System.in);
public static void main(String[] args)
{
String filename;
int maxNum = 20;
int[] intArray = new int[maxNum];
int[] bIntArray = new int[maxNum];
int[] aRanks = new int[maxNum];
int[] bRanks = new int[maxNum];
System.out.println("Enter the name of the input file: ");
filename = ins.next();
Scanner input = null;
try
{
input = new Scanner(new File(filename));
}
catch(FileNotFoundException FNFE)
{
System.err.printf("Could not find the input file %s ", filename);
System.exit(1);
}
//String comment = input.nextLine(); // to go to next line in input
int index = 0,lena=0,lenb=0;
String emptyLine;
String inputstring;
while ((lena<=maxNum&&lenb <= maxNum) && input.hasNextLine())
{
inputstring=input.nextLine();
String[] inputs=inputstring.split(" ");
intArray[lena] = Integer.parseInt(inputs[0]); //assign all first sequence inputs into intArray array
aRanks[lena] = Integer.parseInt(inputs[1]); //assign all second sequence inputs into aRanks array
lena++;
if(inputs.length>2)
{
bIntArray[lenb] = Integer.parseInt(inputs[2]); //assign all third sequence inputs into bIntArray array
bRanks[lenb] = Integer.parseInt(inputs[3]); //assign all fourth sequence inputs into bRanks array
lenb++;
}
}
for(int k=0;k<lena;k++)
System.out.println(intArray[k]);
for(int k=0;k<lenb;k++)
System.out.println(bIntArray[k]);
//ranksByMerge();
}
}