#10674: JAVA 他說程式無法結束所導致錯誤


a5456434 (shawn)


package two;
import java.util.*;
public class two {

public static void main(String[] args) {
int one;
Scanner str = new Scanner(System.in);
one=str.nextInt();


for(int i=0;i<=one;i++){
int a,b,c,d;

a=str.nextInt();
b=str.nextInt();
c=str.nextInt();

if(a==1){
System.out.println(b+c);
}


else if(a==2){
System.out.println(b-c);
}


else if(a==3){
System.out.println(b*c);
}


else if(a==4){
System.out.println(b/c);
}
}
}
}

 

 

請問我哪裡有錯嗎 執行是可以的阿!?

#10689: Re:JAVA 他說程式無法結束所導致錯誤


tomoyaken14 (歐練)


package two;
import java.util.*;
public class two {

public static void main(String[] args) {
int one;
Scanner str = new Scanner(System.in);
one=str.nextInt();


for(int i=0;i<=one;i++){
int a,b,c,d;

a=str.nextInt();
b=str.nextInt();
c=str.nextInt();

if(a==1){
System.out.println(b+c);
}


else if(a==2){
System.out.println(b-c);
}


else if(a==3){
System.out.println(b*c);
}


else if(a==4){
System.out.println(b/c);
}
}
}
}

 

 

請問我哪裡有錯嗎 執行是可以的阿!?

for(int i=0;i<=one;i++)


這個迴圈跑了幾次呢?