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] 삭제
몇 마디 만하겠습니다