This one is a bit tricky. You're going to have to isolate each digit of the integer to determine which one is the largest, so good luck!
Instructions:
Instructions
Input
A line containing a three-digit integer.
173
Output
A line containing a single-digit integer
7
"The code should use If-Else-Elseif statement"
import java.util.Scanner;
public class App {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int number = in.nextInt();
int largestDigit = 0;
while (number > 0) {
int digit = number % 10;
if (largestDigit < digit) {
largestDigit = digit;
}
number = number / 10;
}
System.out.println(largestDigit);
in.close();
}
}
Comments
Leave a comment