编写一个类的方法,其输入参数为一个整数,输出为该整数各个位上的最大数字。
输入格式:
输入一个整数N
输出格式:
输出该整数N各个位上的最大数字
输入样例:
在这里给出一组输入。例如:
59274
输出样例:
在这里给出相应的输出。例如:
9
代码如下:
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner s= new Scanner(System.in);
String a = s.next();
int max=0;
for(int i = 0; i < a.length(); i++)
{
int n = a.charAt(i) - '0';
if(n>max)max=n;
}
System.out.print(max);
}
}