if
package ex3_control_stat;
public class Ex1_if {
public static void main(String[] args) {
//제어문 - 프로그램의 흐름을 제어하는 문법
//조건문 : 조건의 참과 거짓으로 실행을 결정 / if, switch
//반복문 : 조건이 참일 때 명령을 반복 / for, while
/*if(조건식){
* 조건이 참일 때 실행할 명령
* } */
int n=50;
if(n==50) {
System.out.printf("n은 50입니다.\n");
}
}
}
if else
package ex3_control_stat;
import java.util.Scanner;
public class Ex2_if_else {
public static void main(String[] args) {
//조건이 참일 때 실행할 명령과 거짓일 때 실행할 명령이 둘다 존재
// if(조건식) {
// 조건식이 참일 때 실행
// }
// else {
// 조건식이 거짓일 때 실행
// }
int n=49;
if(n==50) {
System.out.printf("n은 50입니다\n");
}
else {
System.out.printf("n은 50이 아닙니다\n");
}
int ball=0,box=0;
Scanner sc = new Scanner(System.in);
System.out.printf("공의 갯수를 입력해주세요 : ");
ball=sc.nextInt();
if(ball%5==0) {
box=ball/5;
}
else {
box=ball/5+1;
}
System.out.printf("필요한 박스의 갯수 : %d\n",box);
}
}