これは、リストが空の場合、それは代わりにゼロを返すの例外をスローするようにどのように私はこのコードを変更できますか?私のコードこのコードに「例外をスローする」を追加するには?
public int Test(int[]n){
if(n.length!=0){
int smallest = n[0];
for(int i = 0; i<n.length ; i++){
if(smallest > n[i]){
smallest = n[i];
return smallest;
}else{
return 0;
}
}
}
ですか
を作成
このコードを試してみてください? – beatrice
ops my bad!リターンステートメントを忘れてしまった! – In6ify
@ In6ifyどの例外をスローしたいですか? – nullpointer