Program:
import java.util.Scanner;
public class Sum_of_last_digits_of_two_given_numbers {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("Enter any two numbers: ");
int a = s.nextInt();
int b = s.nextInt();
String s1 = a+""; //converting integer to string
String s2 = b+""; //converting integer to string
int c = Integer.parseInt(s1.charAt(s1.length()-1)+"") + Integer.parseInt(s2.charAt(s2.length()-1)+"");
System.out.println("Sum of last digits of two given numbers is: "+c);
}
}
Input/Output:
Enter any two numbers:
123
145
Sum of last digits of two given numbers is: 8
0 comments:
Post a Comment