조건문
if 문
int score = 90;
if (score >= 90) {
System.out.println("Grade A");
}
if else 문
if (score >= 90) {
System.out.println("Grade A");
} else {
System.out.println("Grade F");
}
else if 문
if (score >= 90) {
System.out.println("Grade A");
} else if(score >= 80) {
System.out.println("Grade B");
} else if(score >= 70) {
System.out.println("Grade C");
} else {
System.out.println("Grade F");
}
switch 문
int num = 1;
switch(num) {
case 1:
System.out.println("1");
break;
case 2:
System.out.println("2");
break;
case 3:
System.out.println("3");
break;
case 4:
System.out.println("4");
break;
default:
System.out.println("5");
break;
}
반복문
for 문
int sum = 0;
for (int i = 1; i <= 100; i++) {
sum = sum + i;
}
while 문
int intValue10 = 1;
while (intValue10 <= 10) {
System.out.println(intValue10);
intValue10++;
}
do-while 문
Scanner scanner = new Scanner(System.in); // import java.util.Scanner;
String inputString;
do {
System.out.println(">");
inputString = scanner.nextLine();
System.out.println(inputString);
} while(!inputString.equals("q"));
break, continue문
for(int i = 1; i <= 10; i++) {
if(i % 2 != 0) {
continue;
} else if(i == 5) {
break;
}
System.out.println(i);
}