28 673
Assignments Done
98,1%
Successfully Done
In August 2015
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.
Our experts will gladly share their knowledge and help you with programming homework. Keep up with the world's newest programming trends.

Answer on Java | JSP | JSF Question for Abhilash

Question #32324
Q) Write an interactive Java program that adds two integers of up to 50 digits each (Represents integer as an array of digits).
Expert's answer

Answer

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]);
sum[n-1]=sum[n-1]+1;
}
}
for (int d=0; d<a.length();d++) {
System.out.print(sum[d]+" ");
}
}
}

Comments

Assignment Expert
01.07.2013, 10:28

<div>
</div><div>import java.util.ArrayList;</div><div>import java.util.Scanner;</div><div>
</div><div>public class Sum {</div><div>
</div><div>& & // Variables</div><div>& & static ArrayList<Integer> result = new ArrayList<>();</div><div>& & static String a, b;</div><div>& & static String min;</div><div>& & static String max;</div><div>& & static Scanner sc = new Scanner(System.in);</div><div>& & static int j = 0;</div><div>& & static int ii;</div><div>
</div><div>& & public static void main(String args[]) {</div><div>& & & & result.add(0);</div><div>
</div><div>& & & & System.out.print("Enter first number: ");</div><div>& & & & a = sc.next();</div><div>& & & & System.out.print("Enter second number: ");</div><div>& & & & b = sc.next();</div><div>& & & & sc.close();</div><div>& & & & if (a.length() >= b.length()) {</div><div>& & & & & & max = a;</div><div>& & & & & & min = b;</div><div>& & & & }</div><div>& & & & if (a.length() < b.length()) {</div><div>& & & & & & max = b;</div><div>& & & & & & min = a;</div><div>& & & & }</div><div>
</div><div>& & & & ii = max.length() - 1;</div><div>& & & & for (int i = min.length() - 1; i >= 0; i--) {</div><div>& & & & & & int temp = Integer.parseInt(min.substring(i, i + 1))</div><div>& & & & & & & & & & + Integer.parseInt(max.substring(ii, ii + 1));</div><div>& & & & & & if (temp < 10) {</div><div>& & & & & & & & result.set(j, result.get(j) + temp);</div><div>& & & & & & & & result.add(0);</div><div>& & & & & & }</div><div>& & & & & & if (temp > 9) {</div><div>& & & & & & & & result.set(j, result.get(j) + temp - 10);</div><div>& & & & & & & & result.add(0);</div><div>& & & & & & & & result.set(j + 1, 1);</div><div>& & & & & & }</div><div>& & & & & & j++;</div><div>& & & & & & ii--;</div><div>& & & & }</div><div>
</div><div>& & & & while (ii >= 0) {</div><div>& & & & & & & & result.set(j, result.get(j) + Integer.parseInt(max.substring(ii, ii + 1)));</div><div>& & & & & & & & result.add(0);</div><div>& & & & & & j++;</div><div>& & & & & & ii--;</div><div>& & & & }</div><div>
</div><div>
</div><div>& & & & if (result.get(result.size() - 1) != 0) {</div><div>& & & & & & System.out.print(result.get(result.size() - 1));</div><div>& & & & }</div><div>& & & & for (int i = result.size() - 2; i >= 0; i--) {</div><div>& & & & & & System.out.print(result.get(i));</div><div>& & & & }</div><div>& & }</div><div>& lt;/div><div>}</div><div>
</div>

hari
25.06.2013, 12:53

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

Leave a comment

Ask Your question

Link to us

Share with friends

free questions
Questions and Answers
approved by clients
Thank you very much for the accurate solutions. I will definitely be using this service in the near future and I have already recommended it to several friends. Please continue to keep this service as perfect as it is. I will do my utmost to write a positive review on review sites in order to keep your reputation up. Once again, thank you very much!
Gunner on August 2011
solving policy
solving policy
satisfaction
guarantee
paypal
Pay us safely via PayPalPayPal
We deliver professional assignment and homework help for students in USA, UK, Canada, Australia, AE and all over the world.
Terms and Conditions | Privacy Policy | Service
© 2015 BrainRouter LTD. All rights reserved.