chaibs

loop-hw3

Dec 27th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.70 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class hw3 {
  4.  
  5.     public static void main(String[] args) {
  6.         int MaxDigit = 0, num = 0, currentDigit = 0;
  7.  
  8.         Scanner s = new Scanner(System.in);
  9.  
  10.         System.out.println("Please enter a number:");
  11.         num = s.nextInt();// getting a number from user
  12.  
  13.         while (num > 0) {// as long as the num2 bigger then 0 continue
  14.             currentDigit = num % 10;// saving the rightist digit for checking
  15.             if (currentDigit > MaxDigit) {// checking if the current digit is the highest
  16.                 MaxDigit = currentDigit;// saving the highest digit
  17.             }
  18.             num /= 10;// removing the right digit from the number
  19.         }
  20.  
  21.         System.out.println("The highest digit is " + MaxDigit);// result
  22.  
  23.     }
  24.  
  25. }
Advertisement
Add Comment
Please, Sign In to add comment