Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

for some reason the command prompt keeps on asking me for input but I am placing a value on line 12 (sum + one) = sum. If you guys could help me determine whats wrong with it that would be amazing.

import java.util.Scanner;

public class FunnyAverage {
   public static void main(String[] args){          
   Scanner in = new Scanner(System.in);
   System.out.print("How many values to read? ");
   int top = in.nextInt();
   System.out.print("Enter Value: ");
   int one = in.nextInt();
   int number = 0;
   int sum = 0;
   (sum + one) = sum;

   while (number>top){
       while (one % 6 != 0&&one % 17 != 0) {
           System.out.print("Enter Value: ");
           one = in.nextInt(); 
           number++;
       }
   }

   if (sum/top != 0){
       System.out.print("Average: " + sum/top);
   }
   System.out.print("None Divisible");
   }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.2k views
Welcome To Ask or Share your Answers For Others

1 Answer

You meant:

sum = sum + one; // or sum += one;

By command prompt, I think you actually mean the compiler (which can write its error messages to the command prompt). The error message will be stating that the result of (sum + one) is not a variable.

See section 15.26. Assignment Operators of the Java Language Specification, which states:

The result of the first operand of an assignment operator must be a variable, or a compile-time error occurs.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...