14 - 一个整数各个位上的最大数字
Time Limit: 1000 Memory Limit: 65535
Submit: 458 Solved: 284
Description
编写一个类的方法,其输入参数为一个整数,输出为该整数各个位上的最大数字。
Input
输入一个整数N
Output
输出该整数N各个位上的最大数字
Sample Input
59274
Sample Output
9
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
int n;
Scanner scanner = new Scanner(System.in);
n = scanner.nextInt();
int result = getMax(n);
System.out.println(result);
}
public static int getMax(int num)
{
int maxvalue = 0;
while(num!= 0)
{
if(num%10 > maxvalue)
maxvalue = num%10;
num/=10;
}
return maxvalue;
}
}