Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class hw3 {
- public static void main(String[] args) {
- int MaxDigit = 0, num = 0, currentDigit = 0;
- Scanner s = new Scanner(System.in);
- System.out.println("Please enter a number:");
- num = s.nextInt();// getting a number from user
- while (num > 0) {// as long as the num2 bigger then 0 continue
- currentDigit = num % 10;// saving the rightist digit for checking
- if (currentDigit > MaxDigit) {// checking if the current digit is the highest
- MaxDigit = currentDigit;// saving the highest digit
- }
- num /= 10;// removing the right digit from the number
- }
- System.out.println("The highest digit is " + MaxDigit);// result
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment