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:
import java.util.Scanner;
//Implement class Cube
class Main {
public static void main(String[] args) {
System.out.print("Please enter three digits number: ");
Scanner cin=new Scanner(System.in);
int a=cin.nextInt();
int mxDigit=0;//Max digit save here
while(a!=0)
{
mxDigit=Math.max(mxDigit,a%10);
a/=10;
}
System.out.println("Max Digit for given number: "+mxDigit);
}
}
Comments
Leave a comment