두 개의 서로 다른 데이터 유형으로 메소드 오버로드를 구현했습니다. 이것이 내가 코드로 끝난 방법입니다. 하지만 이제 기호 c와 d를 찾을 수 없습니다. 어떤 도움?함수 호출에서 '심볼을 찾을 수 없습니다'를 수정하는 방법은 무엇입니까?
import java.util.*;
import java.lang.*;
public class LargestOfTwoTest{
public static void main(String args[]) throws Exception{
Scanner scan = new Scanner(System.in);
System.out.println("Enter two numbers, and I wiil show you which one's largest!\n");
System.out.println("Enter two numbers: ");
double a = scan.nextDouble();
double b = scan.nextDouble();
if (a==(Math.floor(a))){
int c = (int) a;
}
else{
double c = a;
}
if (b==(Math.floor(b))){
int d = (int) b;
}
else {
double d = b;
}
System.out.print("Largest of the numbers is "+largest(c,d));
}
public static int largest(int x, int y){
if (x>y)
return x;
//System.out.print("Largest of the numbers is "+x);
else
return y;
//System.out.print("Largest of the numbers is "+y);
}
public static double largest(double x, double y){
if (x>y)
return x;
//System.out.print("Largest of the numbers is "+x);
else
return y;
//System.out.print("Largest of the numbers is "+y);
}
}
은 ..이 광고
System.out.print("Largest of the numbers is "+largest(c,d));
에서 오류가 표시
LargestOfTwoTest.java:29 오류 : 기호를(c 및 d)
'c'와 'd'를 귀하의 인보이스 범위에서 제외했습니다 '최대'의 양이온은 오버로드와 아무런 관련이 없습니다. – Mena
단일 범위에서 하나의 변수 선언 만 가질 수 있습니다. 선언을'if'에 넣음으로써 다른 선언을 생성하려는 시도는'if' 블록이 분리 된 범위이고 블록이 완료 되 자마자 선언이 범위를 벗어나기 때문에 작동하지 않습니다. – RealSkeptic
제목을 특정 질문으로 바꾸거나 계속 다운 voted 상태로 유지해야합니다. 그냥 친절한 머리. – samosaris