#java #コンパイルエラー
java言語のBMI計算の下記のコードから間違いを探して修正しなさいというプログラミングについての課題で
import java.util.Scanner;
public class Program {
public void input (){
Scanner scan = new Scanner (System.in);
}
public void compute(){
}
public void output (){
double height = 1.70;
double height = 60.0;
System.out.println (weight / (height * height;
}
public static void main (String[] args){
Program p = new Program ();
p.input();
p.compute();
p.output();
}
}
というコードの13行目のSystem.out.println (weight / (height * height;を
System.out.println (weight / (height * height));に修正して
import java.util.Scanner;
public class Program {
public void input (){
Scanner scan = new Scanner (System.in);
}
public void compute(){
}
public void output (){
double height = 1.70;
double height = 60.0;
System.out.println (weight / (height * height));
}
public static void main (String[] args){
Program p = new Program ();
p.input();
p.compute();
p.output();
}
}
コメント
Program.java:12: error: variable height is already defined in method output()
double height = 60.0;
^
Program.java:13: error: cannot find symbol
System.out.println (weight / (height * height));
^
symbol: variable weight
location: class Program
2 errors
と、コメントが出ました
上記の修正であっているはずなのですがコンパイルエラーだと表示されます
これはどう修正すればいいのでしょうか
回答2件
あなたの回答
tips
プレビュー