Computer Science, asked by apnafamily4987, 1 month ago

write a program to print the sum of a number with its unit digit and then display the unit digit of the sum in java​

Answers

Answered by arjun8114
0

Answer:

Declare a variable to store the sum and set it to 0. Repeat the next two steps till the number is not 0. Get the rightmost digit of the number with help of the remainder ‘%’ operator by dividing it by 10 and add it to sum. Divide the number by 10 with help of ‘/’ operator to remove the rightmost digit. Print or return the sum.

Explanation:

brainliest pls

Answered by dreamrob
5

Program:

import java.util.*;

public class Main

{

public static void main(String[] args)

{

 Scanner Sc = new Scanner(System.in);

 System.out.print("Enter a number : ");

 int n = Sc.nextInt();

 int sum = n + n%10;

 System.out.println("Sum of the number with its unit digit \n" + n + " + " + (n%10) + " = " + sum);

 System.out.println("The unit digit of the sum = " + (sum%10));

}

}

Output:

Enter a number : 149

Sum of the number with its unit digit  

149 + 9 = 158

The unit digit of the sum = 8

Similar questions