Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

java - Unexpected type Average

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...