1. ## Help adding Intergers in array(s)

I'm having issues adding the numbers in the array together. I know I need a loop to start at position 19 and move downward...but I'm at a loss...

any help would be greatly appreciated...I'm pulling my hair out.

import
java.util.Scanner;

public
class LargeNums {

publicstaticfinalintMAXSIZE = 20;
publicstaticvoid main(String[] args) {

Scanner keyboard = new Scanner(System.in);
char x ,y;
int c1 = MAXSIZE - 1;
String input1, input2;

int [] num1 = newint[MAXSIZE];
int [] num2 = newint[MAXSIZE];
int [] num3 = newint[MAXSIZE];

System.out.println("Please enter two positive integers with less than " + MAXSIZE + " digits" );
System.out.print("Please enter the first integer: ");
input1 = keyboard.nextLine();
System.out.print("Please enter the second integer: ");
input2 = keyboard.nextLine();

for (int i= input1.length() -1; i>= 0; i--){

x = input1.charAt(i);

if(Character.isDigit(x)){

num1[c1--] = x-48;
}
}
for (int i= input1.length() -1; i>= 0; i--){

y = input1.charAt(i);

if(Character.isDigit(y)){

num2[c1--] = y-48;

}
}
for (int z = 0; z<num1.length; z++){
System.out.print(num1[z]);
}

}

}

2. Did you convert your string input to int? Integer.parseInt() ..

If that does not work then try to debug it a step at a time by commenting out your code. Good Luck.

3. well you have 2 options here, you can either use Integer.parseInt() ... and just add the numbers, much easier. If you're required to do it using arrays (I'm assuming this is homework) then you need to think about the problem a bit.

You've managed to store the number in an array but they're all just digits 0-9. You've already got the loop part more or less correct, you just need to have an accumulator of some sort to get the actual value before adding them. This really becomes a matter of math, maybe work it out on paper first.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•