Write a program that input five-digit number and calculate sum of first and last digit of that number.

 

public static void main(String[] args) {

Scanner cin= new Scanner(System.in);

int n,a,b,c,d,sum;

System.out.println(“Enter 5 digit number”);

n=cin.nextInt();

a=n/10000;

n=n%10000;

b=n/1000;

n=n%1000;

c=n/100;

n=n%100;

d=n/10;

n=n%10;

sum=a+n;

System.out.println(“Sum= Of frst & last Digit is=”+sum);

}

}

Output

run:
Enter 5 digit number
92311
Sum= Of frst & last Digit is=10
BUILD SUCCESSFUL (total time: 13 seconds)

Leave a Reply

Your email address will not be published. Required fields are marked *