運行后從鍵盤輸入三個整數(shù),輸出其中的最大數(shù),代碼哪里錯誤
package cn.test;
import java.util.Scanner;
public class Experiment1_6 {
public static void main(String[] args){
? ? ??
? ? ? ? ? Scanner input= new Scanner (System.in);?
? ? ? ? ? int numbers[] = input.nextInt();
? ? ? ? ? ?for(int i=0;i<3;i++)
? ? ? ? ? ?{
? ? ? ? ? int max=0;
? ? ? ? ? if (numbers[i] >max){
? ? ? ? ?max = numbers[i]; }
? ? ? ? ? ? System.out.println(max);
? ? ? ? ? ? }
? ? ? ? }
}//運行后從鍵盤輸入三個整數(shù),輸出其中的最大數(shù)
2016-10-17
import java.util.Scanner;
public class Experiment1_6?{
public static void main(String[] args){
? ? ??
? ? ? ? ? int numbers[] = new int[3];
? ? ? ? ? int max=0;
? ? ? ? ? for(int i=0;i<3;i++){
? ? ? ? ? ??
? ? ? ? ?Scanner input= new Scanner (System.in);?
? ? ? ? ? ? ? numbers[i]=input.nextInt();
? ? ? ? ? ? ? if (numbers[i] >max){
? ? ? ? ? ? ? ? ? max = numbers[i];?
? ? ? ? ? ? ? ?}?
? ? ? ? ?}
? ? ? ? ? System.out.println(max);
?}
}
2016-10-17
for循環(huán)里應該先取得三個整數(shù),然后再在for循環(huán)外面判斷輸出最大值