I suggest you start by getting your program to work with just the first 3 lines
ID: 3764664 • Letter: I
Question
I suggest you start by getting your program to work with just the first 3 lines of data (3 answers) as those will be easy with plain old int data. Then take the challenge of more lines. When I grade these, I will use different numbers, so do not code just for these exact data.
Submit a Class called Sum.java with the following main() method:
and a processFile method as used below!!!!
import java.io.*; // NO you cannot use BigInteger to do this!
import java.util.*; // These are the ONLY imports allowed
public class Sum {
public static final int DIGITS = 50; // maximum number of digits
// ... lots more code follows .....
Above requires two (or more) methods, plus main and processFile. In addition, I REQUIRE two additional methods in your solution, and at least one of these methods must use an array as a passed parameters (two arrays also OK). For example, you might write some sort of "add" method that does the actual addition of int[] arrays as passed parameters. I say int[] because that's how we do addition, one digit at a time, treat each digit as an element of an int[], and write the rules of addition, you know them well, time to code it!!!
this is file sum on text
Explanation / Answer
public class Sum
{
public static void main(String args[]) throws FileNotFoundException
{
File file = new File("sum.txt");
Scanner scanner = new Scanner(file);
int[][] myInts = new int[wordSize][];
int mySpot = 0;
while (scanner.hasNextLine())
{
Scanner scanner1 = new Scanner(scanner.nextLine());
while (scanner1.hasNext())
{
String s = scanner1.next();
int i;
for ( i= 0; i < wordSize - s.length(); i++)
{
myInts[i][mySpot] = 0;
}
i--;
for (int j=0;j < s.length(); i++,j++)
{
myInts[i][mySpot] = Character.digit(s.charAt(i), 10);
}
mySpot++;
}
}
for(int i = 0; i < myInts.length; i++)
{
}
System.out.println(Character.getNumericValue(myInts[0]));
System.out.println(Arrays.toString(myInts));
}
}