我正在試驗代碼,我想知道如何才能打印已包含值的數組?如果我要添加諸如「一週的溫度是:」然後將列表打印出來給用戶。 這是我的代碼:正在打印已包含值的數組
public static void main(String[] args) {
Scanner keyboard=new Scanner(System.in);
System.out.println("How many temperatures?");
int size=keyboard.nextInt();
int temp[]=new int[size];
System.out.println("Please enter "+temp.length+" temperatures");
double sum=0;
for(int i=0;i<temp.length;i++){
temp[i]=keyboard.nextInt();
sum=sum+temp[i];
}
double average=sum/temp.length;
System.out.println("The average temperature is: "+average);
for(int i=0;i<temp.length;i++){
if (temp[i]>average){
System.out.println("Above average: "+temp[i]);
}
else if(temp[i]<average){
System.out.println("Below average: "+temp[i]);
}
else if(temp[i]==average){
System.out.println("Equal to average "+temp[i]);
}
}
}
現在有什麼確切的問題? :) – Muhammad
我不知道如何以單獨輸入的值彼此排列的方式打印數組 –
現在問題已解決,因爲@turingcomplete回答了您的問題? :) – Muhammad