Your physics homework can be a real challenge, and the due date can be really close - feel free to use our assistance and get the desired result.
Be sure that math assignments completed by our experts will be error-free and done according to your instructions specified in the submitted order form.
Get a free quote.
Check the website
 Easy as ABC! Just provide us with clear instructions and wait for the completed assignment.

# Programming:  Java | JSP | JSF Java | JSP | JSF Question #32324 from Abhilash

Q) Write an interactive Java program that adds two integers of up to 50 digits each (Represents integer as an array of digits).

import java.util.* ;

public class Calculator {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.print("Enter the first integer:");
String a = s.nextLine();
System.out.print("Enter the second integer:");
String b = s.nextLine();
int[] num1 = new int[a.length()];
int[] num2 = new int[b.length()];
for (int i=0;i<a.length();i++) {
num1[i] = (int) a.charAt(i);
num2[i] = (int) b.charAt(i);
}
int[] sum = new int[a.length()];
for (int n=b.length()-1;n>=0;n--)
{
if (num1[n]+num2[n]<10)
{
sum[n]=num1[n]+num2[n];

}
if (num1[n]+num2[n]>=10)
{
sum[n]=(num1[n]+num2[n])%10;
sum[n-1]=sum[n-1]+1;
}
}
for (int d=0; d<a.length();d++) {
System.out.print(sum[d]+" ");
}
}
}

2013-06-25 12:53:37

Q) Write an interactive Java program that adds two integers of up to 50 digits each (Represents integer as an array of digits).

2013-07-01 10:28:42

import java.util.ArrayList;
import java.util.Scanner;

public class Sum {

// Variables
static ArrayList<Integer> result = new ArrayList<>();
static String a, b;
static String min;
static String max;
static Scanner sc = new Scanner(System.in);
static int j = 0;
static int ii;

public static void main(String args[]) {

System.out.print("Enter first number: ");
a = sc.next();
System.out.print("Enter second number: ");
b = sc.next();
sc.close();
if (a.length() >= b.length()) {
max = a;
min = b;
}
if (a.length() < b.length()) {
max = b;
min = a;
}

ii = max.length() - 1;
for (int i = min.length() - 1; i >= 0; i--) {
int temp = Integer.parseInt(min.substring(i, i + 1))
+ Integer.parseInt(max.substring(ii, ii + 1));
if (temp < 10) {
result.set(j, result.get(j) + temp);
}
if (temp > 9) {
result.set(j, result.get(j) + temp - 10);
result.set(j + 1, 1);
}
j++;
ii--;
}

while (ii >= 0) {
result.set(j, result.get(j) + Integer.parseInt(max.substring(ii, ii + 1)));
j++;
ii--;
}

if (result.get(result.size() - 1) != 0) {
System.out.print(result.get(result.size() - 1));
}
for (int i = result.size() - 2; i >= 0; i--) {
System.out.print(result.get(i));
}
}

}