SECOND LARGEST DIGIT

Write a program to input a numbers and display their second largest digit.

 

import java.util.*; class SecondLargestDigit { public static void main() { int x,largest=0,sl=0,i=0,temp; System.out.println("Enter any integer \n"); Scanner in = new Scanner(System.in); x = in.nextInt(); temp=x; for(;x>0;x=x/10) { if(x%10>largest) largest= x%10; } x=temp; for(;x>0;x=x/10) { if(x%10>sl && largest !=x %10) sl=x%10; } System.out.println("Second largest digit is "+sl); } }


For any desired program, please comment below. We will try our best to make that program available.

Comments

Popular Posts