코드는 내가 값을 50으로 입력 할 때 작동하고 태양 조건에 대한 값을 제공 할 때 작동하지 않습니다.

차이 타냐 데시 카르

suncondition에 대한 값을 제공 할 때 if 루프에 들어가기 위해 고군분투하는 사용자 입력에 스캐너 사용

@SuppressWarnings("resource")
Scanner temp = new Scanner(System.in);
int temperature;
System.out.print("Enter the temperature : ");
temperature=temp.nextInt();
@SuppressWarnings("resource")
Scanner suncon= new Scanner(System.in);
String suncondition;
System.out.print("Enter the Sun condition : ");
suncondition=suncon.nextLine();

if ((temperature==50) || (suncondition=="Sunny")){
    System.out.println(" This is tooo hot");
}
알렉스

== 메모리에서 동일한 객체를 참조하는 경우 비교하므로 여기서는 그렇지 않으므로 거짓이됩니다.

여기에서 equals 메소드를 사용할 수 있습니다. 이것은 문자열의 데이터 / 내용을 기준으로 비교합니다.

@SuppressWarnings("resource")
Scanner temp = new Scanner(System.in);
int temperature;
System.out.print("Enter the temperature : ");
temperature=temp.nextInt();
@SuppressWarnings("resource")
Scanner suncon= new Scanner(System.in);
String suncondition;
System.out.print("Enter the Sun condition : ");
suncondition=suncon.nextLine();

if ((temperature==50) || (suncondition.equals("Sunny"))){
    System.out.println(" This is tooo hot");
}

이것에 대해 더 알고 싶다면 여기에 좋은 기사가 있습니다.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Related 관련 기사

뜨겁다태그

보관