Using jGrasp and the Software Development Kit, write a program in response to th
ID: 647913 • Letter: U
Question
Using jGrasp and the Software Development Kit, write a program in response to the following prompt:
Write a program that prompts the user to input an integer and then outputs both the individual digits of the number and the sum of the digits. For example, the program should: ouput the individual digits of 3456 as 3 4 5 6 and the sum as 18, output the individual digits of 8030 as 8 0 3 0 and the sum as 11, output the individual digits of 2345526 as 2 3 4 5 5 2 6 and the sum as 27, output the individual digits of 4000 as 4 0 0 0 and the sum as 4, and output the individual digits of -2345 as 2 3 4 5 and the sum as 14.
Explanation / Answer
The same question was resolved before with different figures. Please input your figure to get your answer. Let me know if you face any issue. Please rate if I succeeded in helping you.
old question
Using jGrasp and the Software Development Kit, write a program in response to the following prompt:
Write a method, reverseDigit, that takes an integer as a parameter and returns the number with its digits reversed. For example, the value of reverseDigit(12345) is 54321. Also, write a program to test your method.
To submit your compiled Java code for this assignment, compress the .java file into a single .zip file. Submit this .zip file to the link below.
Answer
01
import java.util.Scanner;
02
03
public class Assignment7
04
{
05
06
public void reverseInteger()
07
{
08
Scanner input = new Scanner( System.in );
09
10
System.out.print( "Enter an integer (-1 to exit): " );
11
int number = input.nextInt();
12
13
while ( number != -1 )
14
{
15
System.out.printf( "%d reversed is %d ",
16
number, reverseDigits( number ) );
17
18
System.out.print( "Enter an integer (-1 to exit): " );
19
number = input.nextInt();
20
}
21
}
22
23
public int reverseDigits( int number )
24
{
25
int reverseNumber = 0;
26
int placeValue;
27
28
while ( number > 0 )
29
{
30
placeValue = number % 10;
31
number = number / 10;
32
reverseNumber = reverseNumber * 10 + placeValue;
33
}
34
35
return reverseNumber;
36
}
37
}
38
public class Assignment7Test
39
{
40
public static void main( String args[] )
41
{
42
Reverse application = new Reverse();
43
application.reverseInteger();
44
}
45
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.