Advertisement
Guest User

Question 3 loops

a guest
Jun 27th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.83 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4. public class q3 {
  5.  
  6.     public static void main(String[] args) {
  7.         // TODO Auto-generated method stub
  8.  
  9.         Scanner S=new Scanner(System.in);
  10.        
  11.         System.out.println("enter number:");
  12.         int userNum= S.nextInt();           //the user enter number
  13.        
  14.        
  15.         int biggerNum= userNum%10;      //installed the variable to the result <-- the left digit
  16.                
  17.         int HuserNum= userNum/10;       // installed the helper variable <-- userNum lass the left digit
  18.        
  19.         while (HuserNum > 0) {      // run as long as HuserNum up to 0
  20.            
  21.             if (biggerNum < HuserNum%10) {  //if biggerNum greater than the left digit
  22.                
  23.                 biggerNum= HuserNum%10;     // biggerNum <-- the left digit
  24.             }
  25.            
  26.             HuserNum/=10;       // remove the right digit
  27.            
  28.         }
  29.        
  30.         System.out.println("the bigest digit is: "+ biggerNum); // print the result
  31.        
  32.     }
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement