While(3)
-
[Eclipse] 누적계산기
- while, if문을 이용 - 처음에 input 2개를 입력받아 더한 후, 100까지 누적 더하기를 해주는 계산기 System.out.println("100을 초과하면 종료하는 누적계산기입니다. \n"); Scanner sc = new Scanner(System.in); System.out.print("입력1: "); int input1 = sc.nextInt(); System.out.print("입력2: "); int input2 = sc.nextInt(); int sum = input1 + input2; System.out.println("현재 누적값은 " + sum + "입니다.\n"); while(sum 100) { System.out.println("누적값이 100을 초과하여 종료합니다!")..
2021.06.17 -
[Eclipse] 가위바위보 게임
- while문과 if문, random값을 사용 - Random값을 1~3까지 생성한다 [1:가위, 2:바위, 3:보] - input값을 받아서 Random값과 비교해 이길 때 까지 게임을 한다. int random = (int)(Math.random() * 3) + 1; //가위:1, 바위:2, 보:3 Scanner sc = new Scanner(System.in); System.out.println("이길때까지 가위바위보!"); while(true) { System.out.print("입력하세요(가위:1, 바위:2, 보:3): "); int input = sc.nextInt(); System.out.println("나는 : " + input); System.out.println("컴퓨터는 : " + ..
2021.06.17 -
[Eclipse] 조건문, 반복문
* 조건문(if, switch) - Java에서 조건문은 if문과 switch문 두 가지 뿐이다. - if문이 주로 사용되며, 경우의 수가 많은 경우 switch문을 사용할 것을 고려한다. - 모든 switch문은 if문으로 변경이 가능하지만, if문은 switch문으로 변경할 수 없는 경우가 많다. *if - if문은 if, if-else, if-else if-else의 세가지 형태가 있다. - 조건식의 결과는 반드시 true 또는 false이어야 한다. if(조건식1) { //조건식1의 결과가 true일때 수행될 문장들 }else if (조건식2){ //조건식1의 결과가 false, 조건식2의 결과가 true일때 수행될 문장들 }else{ //모든 조건식의 결과가 false일때 수행될 문장들 } //..
2021.06.16