Quantcast

A community for students. Sign up today!

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

math456

  • 2 years ago

Need help!! Java's type int has a limit on how large an integer it can store. This limit can be circumvented by representing an integer as an array of digits. Write and interactive program that prompts for two integers of up to 50 digits each, adds them together, and correctly prints out the sum. One need deal only with nonnegative integers.

  • This Question is Closed
  1. math456
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    @KonradZuse @Hero @phi @msmithhova?

  2. math456
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    @eSpex

  3. Chris2332
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Wanna show as your attempt on how you tackled the problem? Pseudocode maybe? Where is your difficulty?

  4. rsmith6559
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Align, deal with one digit at a time, concatenate. I'd do it recursively.

  5. math456
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    This is what I have so far.. import java.util.Scanner; public class Integer { public static void main(String [] args) { String s1 = {7,8,9,6,0,9,7,3,2,6}; String s2 = {9,4,8,5,9,3,8,9,2,8}; results = {s1+s2}; let i=50; for(int i=s1.length()-1; i>=0; i--) { //loop that runs from left to right if(s1[i] + s2[i] + results[i+1]) { s1[i] + s2[i] + results[i+1] < 9); results[i+1]++; } else { results = s1[i] + s2[i] + result[i+1]; } System.out.print(s1[i]=s1.charAt(i)-0); } } }

  6. math456
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    @Chris2332 @rsmith6559

  7. KonradZuse
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I'm a bit confused with this.... An Integer is 32 million, that isn't 50 digits... http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html t: The int data type is a 32-bit signed two's complement integer. It has a minimum value of -2,147,483,648 and a maximum value of 2,147,483,647 (inclusive). For integral values, this data type is generally the default choice unless there is a reason (like the above) to choose something else. This data type will most likely be large enough for the numbers your program will use, but if you need a wider range of values, use long instead.

  8. math456
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    yea so did it this way! import java.util.Scanner; public class Integer { public static void main(String [] args) { String s1 = console.next(); String s2 = console.next(); s1[i] = s1.chartAt(i) - '0'; //assigns the value s2[i] = s2.chartAt(j) - '0'; results = (" "); let j=50; char c = (j + '0'); // assigns to charcter c for(int i=s1.length()-49; i>=0; i--) { //loop that runs from left to right if(s1[i] + s2[i] + results[i+1]) { results[i+1]++; } else { results = (s1[i] + s2[i] + results[i+1]); } //if sum is greater than 9 then it will add to the bext value System.out.print(s1[i] + s2[i] + results[i+1] < 9); System.out.print(results[i+1] <9); } } }

  9. math456
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    its showing me 26 errors...

  10. math456
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    @KonradZuse

  11. KonradZuse
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    :O.....

  12. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Ask a Question
Find more explanations on OpenStudy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.