Java Eclipse TestMaxOfDigits
我想写一个程序,读取一个整数,并向用户显示该数字的最大位数。我的代码有什么问题
我在这里尝试了一些代码,但eclipse不允许! 正确的形式是什么?我应该如何将其更改为正确的形式
import java.util.Scanner;
public class TestMaxDigits {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
long n;
long max = 0;
if(n%10>max){
max = n%10 ;
System.out.println("max ="+max) ;
}
}
}
# 1 楼答案
您应该使用
hasNextInt()
和nextInt()
(或hasNextLong()
和nextLong()
)方法从Scanner
类读取整数表单用户输入请尝试使用以下代码:
你应该详细描述你到底想做什么
# 2 楼答案
它不起作用,因为逻辑上你的代码有缺陷
这里有一种方法