java
-
4. control - (3) Lotto3 (로또 중복발생 방지)java/코드 리뷰 2020. 3. 23. 15:03
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 package control; public class Lotto3 { public static void main(String[] args) { int n1 = 0; int n2 = 0; int n3 = 0; int n4 = 0; int n5 = 0; int n6 = 0; int num = 0; for(int i=1; i
-
4. control - (2) Lotto2 (for, if문 사용)java/코드 리뷰 2020. 3. 23. 15:02
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 package control; import java.util.Scanner; public class Lotto2 { public static void main(String[] args) { /* 금액을 입력받는다 금액은 1000원 단위의 값만 입력받는다 로도 번호를 입력된 금액만큼 발행한다 1000원당 1세트씩 발행한다 */ System.out.print("금액을 입력하세..
-
4. control - (1) Lotto (Math.random())java/코드 리뷰 2020. 3. 23. 14:58
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 package control; public class Lotto { public static void main(String[] args) { int num1 = (int) (Math.random()*45 + 1); int num2 = (int) (Math.random()*45 + 1); int num3 = (int) (Math.random()*45 + 1); int num4 = (int) (Math.random()*45 + 1); int num5 = (int) (Math.random()*45 + 1); int num6 = (int) (Math.random()*45 + 1); System.out.println(num1 + ", " + num2..
-
4. control - (5) IfDemo5 (중첩 if문)java/코드 리뷰 2020. 3. 23. 14:57
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 package control; public class IfDemo5 { public static void main(String[] args) { // 중첩 if문 // if문의 블록 내에 다른 if문을 포함시키는것 /* 성적표 출력하기 60점 이상인 경우 합격, 그 외에는 불합격 단, 합격자 중에서 성적이 100점 이상인 경우 전액 장학금 지급 96점 이상인 경우 반액 장학금 지급 단, 성적이 40점 이하인 경우 다음 회차 응시기회를 박탈 */ int score = 80; if (score >= 60) { System.out.print..
-
4. control - (4) IfDemo4 (고객 등급)java/코드 리뷰 2020. 3. 23. 14:02
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 package control; import java.util.Scanner; public class IfDemo4 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); /* 고객의 등급(일반, 로얄, 플래티넘 중 하나)과 총구매금액을 입력받는다. 고객의 등급이 플래티넘인 경우 구매금액의 10%를 할인한다 로얄인 경우 구매금액의 3%를 할인한다 일반인 경우 구매금액의 1..
-
4. control - (3) IfDemo3 (if-else if문)java/코드 리뷰 2020. 3. 20. 15:05
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 package control; import java.util.Scanner; public class IfDemo3 { public static void main(String[] args) { /* if ~ else if ~ else if ~ else 문 3개 이상의 경우의 수를 처리해야 할 때 사용되는 조건문 if (조건식1) { 조건식1의 연산결과가 true로 판정될 때 실행될 수행문; } else if (조건식2) { 조건식2의 연산결과가 true로 판정될 때 실행될 ..
-
4. control - (2) IfDemo2 (if문 - 짝수홀수)java/코드 리뷰 2020. 3. 20. 14:36
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 package control; import java.util.Scanner; public class IfDemo2 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); // 숫자를 입력받아서 짝수인 경우는 "짝수", 아닌 경우는 "홀수"라고 표시 // 짝수는 2의 배수 int number = sc.nextInt(); if (number % 2 == 0) { System.out.println(number + "은 짝수입니다"); } else { System.out.println(number + "은 홀수입니다"); } } }