Я создаю программу для разработки min, max и avg для ввода пользователей. Когда пользователь вводит 0 или отрицательное число, программа выходит из цикла.Ошибка в том случае, если оператор условный
В настоящее время я работаю над созданием входного процессора. Но у меня есть некоторые ошибки. Раньше я не использовал условные обозначения, поэтому я должен где-то ошибаться.
Также будет оценено любое предположение о том, как я мог бы сделать это лучше.
Ошибка:
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....");
}
}
}
}
Три синтаксиса ошибки: иных ошибок 'input_into.hasNextint()) {' -> 'input_into.hasNextInt()) {', 'если (input_into.nextInt()! = 0) || input_into.nextInt < 0){' -> 'if (input_into.nextInt()! = 0 || input_into.nextInt() <0) {' (здесь два) –
ошибка на самом деле говорит вам, что не так. просто продолжайте смотреть на нее, пока не получите ее. – GottZ