我正在构建一个程序来计算用户输入的最小值,最大值和平均值。 当用户输入0或负数时,程序退出循环。if语句中的错误有条件
我目前正在构建输入处理器。但我有一些错误。之前我还没有使用过这些条件,所以我必须在那里犯一个错误。
还有任何建议如何我可以做得更好,将不胜感激。
错误:
questionAvg.java:17: error: illegal start of expression
if(input_into.nextInt() !=0) || input_into.nextInt < 0){
^
questionAvg.java:17: error: ';' expected
if(input_into.nextInt() !=0) || input_into.nextInt < 0){
^
questionAvg.java:19: error: 'else' without 'if'
} else{
代码:
import java.util.*;
public class questionAvg
{
public static void main(String[]args)
{
Scanner input_into = new Scanner(System.in);
ArrayList<Integer> collector = new ArrayList<Integer>();
System.out.println("Enter 0 or a negative number to end input");
System.out.println("Enter a positive integer to populate the arraylist");
while (input_into.hasNextint()){
System.out.println("Type another int or exit");
if(input_into.nextInt() !=0) || input_into.nextInt < 0){
collector.add(input_into.nextInt());
} else{
System.out.println("You entered 0 or a negative number. Now calculating....");
}
}
}
}
三语法errros错误:'input_into.hasNextint()){' - >'input_into.hasNextInt()){','如果(input_into.nextInt()!= 0)|| input_into.nextInt < 0){' ->'if(input_into.nextInt()!= 0 || input_into.nextInt()<0){'(这里是两个) –
错误实际上告诉你什么是错误的。只要不断盯着它,直到你得到它。 – GottZ