누군가가 "If else statement"를 "switch"로 바꿀 수 있는지 궁금합니다. 의사 코드가 있습니다. 도와주세요."If else statement"를 switch 문으로 변경하십시오.
IF month is 1,2, or 3, season = "Winter
Else if month is 4, 5, or 6, season = "Spring"
Else if month is 7,8, 9, season = "Summer"
Else if month is 10,11, or 12, season = "Fall"
If season is "Winter", season = "Spring"
Else if season is "Spring", season = "Summer"
Else if season is "Summer", season = "Fall"
Else season = "Winter"
2.My 코드는 switch 문에 첫번째 부분을 변경해야
import java.util.Scanner;
public class mylab
{
public static void main(String[] args)
{ Scanner in = new Scanner(System.in);
int month;
int day;
String season= "seasons";
System.out.print("type a two digit month");
System.out.print(" and day");
month = in.nextInt();
day = in.nextInt();
String fall = " fall";
String winter = " winter ";
String summer = " summer";
String spring = " spring";
System.out.print(" Month="+ month +" Day= "+day);
if(month <= 3)
{ System.out.println(" Winter");
season= winter; }
else if (month <=6)
{ System.out.println(" Spring ");
season=spring; }
else if (month<= 9)
{ System.out.println(" Summer ");
season= spring; }
else if (month<=12)
{ System.out.println(" Fall");
season= fall; }
3.I입니다. 이것은 내가 지금까지 가지고있는 것입니다.
switch(month)
{ case 1: season= " winter";if (month <= 3) ;break;
case 2: season= " spring"; if (month <= 6) ;break;
case 3: season = " summer"; if (month <= 9); break;
case 4: season= " fall"; if (month <= 12); break ;
}
그러나 작동하지 않습니다.
이 전적으로 INV이기 때문에 그것은 작동하지 않을 것입니다 alid 구문. 이에 대해서는 [Java Trails] (http://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html)를 참조하십시오. – Makoto
나에게 수업을위한 숙제 같은 냄새 ... – mellowfish