Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class BiggestDigit {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int num, bigDigit = 0;
- System.out.println("Please enter a number: ");
- num = sc.nextInt();
- do {
- //Check if the next digit is bigger. Update bigDigit if so.
- bigDigit = bigDigit > num % 10 ? bigDigit : num % 10;
- num /= 10; // Omit the right digit
- } while(num > 0);// As long as there are digits
- System.out.printf("The biggest digit is: %d", bigDigit);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement