意見交換
ユークリッドの互除法を用いた最大公約数の計算のプログラミング
import java.util.Scanner;
public class Program {
int x = 104;
int y = 72;
int r = temp;
public void input (){
Scanner scan = new Scanner (System.in);
}
public void compute(){
if(x < y){
temp = x;
x = y;
y = temp;
}
while (y != 0){
r = x % y;
x = y;
y = r;
}
}
public void output (){
System.out.println(x);
}
public static void main (String[] args){
Program p = new Program ();
p.input();
p.compute();
p.output();
}
}
エラーメッセージ
Program.java:5: error: cannot find symbol
int r = temp;
^
symbol: variable temp
location: class Program
Program.java:12: error: cannot find symbol
temp = x;
^
symbol: variable temp
location: class Program
Program.java:14: error: cannot find symbol
y = temp;
^
symbol: variable temp
location: class Program
3 errors
error: cannot find symbolが出る原因としてimportの不足、変数名の間違い、大文字小文字の間違いの可能性を考えて、
importにjava.utilがあるか確認、変数の確認、大文字小文字の確認、出力の変数を変えるなどしましたが、エラーになりました
他にどのような原因が考えられますか
回答1件
あなたの回答
tips
プレビュー
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
2023/03/22 07:28