Computer Science Homework Solutions
Problem
#133819

Reverse Integer

There is an attachment with this problem.  Please review the attachment and conjunction with the problem being posted.  The problem is below and currently I am stuck.

"  Write a method that takes an integer value and returns the number with its digits reversed.  For example, given the number 7631, the method should return 1367.  Incorporate the method into an application that reads a value from the user and displays the results."

Attached file(s):
Attachments
Reverse Integers.doc  View File

Attachment Content Summary (Note: view attachment at the above link before purchasing. Actual attachment content may vary slightly from that shown below.)

Reverse Integers.doc
// Reverse integer

import java.util.Reverse; // program uses class Reverse

public class ReverseIntegers

{

Public static void main(String args [])

{

int number;

int reverse(int);

main()

{

cout << "Enter an Integer value of 4 digits = ";

cin >> number;

cout << "The number with its digits reversed is = ";

number=abs(number);

if (number<10)

cout << setw(1) << setfill('0') << reverse(number) << endl;

else if (number<100)

cout << setw(2) << setfill('0') << reverse(number) << endl;

else if (number<1000)

cout << setw(3) << setfill('0') << reverse(number) << endl;

else

cout << "Sorry, number is not valid.";

return 0;

}

int reverse(int number)

{

int digit1, digit2, digit3, digit4;

if (number<10)

return number;

else if (number<100)

{

digit1=div(number,10).quot;

digit2=div(number,10).rem;

return (digit2*10 + digit1);

}

else if (number<1000)

{

digit1=div(number,100).quot;

number=div(number,100).rem;

digit2=div(number,10).quot;

digit3=div(number,10).rem;

return (digit3*100 + digit2*10 + digit1);

}

return 0;

}
Solution
What is this?
By OTA - Overall OTA Rating
Debraj Banerjee, MIT (IP) - 4.8/5
Purchase Cost Now
$2.19 CAD (was ~$7.98)
Included in Download
  • Plain text response
  • Attached file(s):
    • Reverse.java
    • Console.java
$2.19 Instant Download
Add to Cart
Why you can trust BrainMass.com
  • Your Information is Secure
  • Best Online Academic Help Service
  • Students find real academic Success
Related Solutions
  • Javascript - One interesting application of computers is the drawing of graphs and bar charts (sometimes called histograms). Write a script that reads five numbers between 1 and 30. For each number read, outpu ...
  • Java Integer - Write program segments that accomplish each of the following tasks: a) Calculate the integer part of the quotient when integer a is divided by integer b. b) Calculate the integer remainder when ...
  • Create and ASP.NET Application - Use Visual Studio.NET 2005 to create an ASP.NET application that displays output from the Amazon web service. Add good documentation to the code. Furthermore, create a user-friendly interface. Name ...
  • Debugging Java Code - ****This needs to be written in Java***** The TestCircle class is a Java application that creates a Circle object using the class, Circle, which incorporates the class, Shape. The TestCircle class ...
  • Java Applet that displays the 13 standard colors - Write an Java Applet that displays the 13 standard colors available in Java (back, blue, cyan, darkGray, gray, green, lightGray, magenta, orange, pink, red, white and yellow) in a set of 13 filled rec ...
Browse