Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.ohgiraffers.section01.conditional.level01.basic;

import java.util.*;
public class Application1 {

public static void main(String[] args) {
Expand All @@ -13,7 +13,14 @@ public static void main(String[] args) {
* -- 출력 예시 --
* 양수다.
* */

Scanner sc = new Scanner(System.in);
System.out.print("정수를 하나 입력하세요 : ");
int x = sc.nextInt();
if(x<0) {
System.out.println("양수가 아니다.");
}else{
System.out.println("양수다.");
}
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.ohgiraffers.section01.conditional.level01.basic;

import java.util.*;
public class Application2 {

public static void main(String[] args) {
Expand All @@ -13,7 +13,14 @@ public static void main(String[] args) {
* -- 출력 예시 --
* 홀수다.
* */

Scanner sc = new Scanner(System.in);
System.out.print("정수를 하나 입력하세요 : ");
int x = sc.nextInt();
if(x%2==0){
System.out.println("짝수다.");
}else {
System.out.println("홀수다.");
}
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.ohgiraffers.section01.conditional.level02.normal;

import java.util.*;

public class Application1 {

public static void main(String[] args) {
Expand All @@ -8,7 +10,17 @@ public static void main(String[] args) {
* 홀수이면 "홀수다.", 홀수가 아니면 "짝수다." 라고 출력하세요.
* 단, 1~10 사이의 정수가 아닌 경우 "반드시 1~10 사이의 정수를 입력해야 합니다." 를 출력하세요.
* */

Scanner sc = new Scanner(System.in);
System.out.print("정수를 하나 입력하세요 : ");
int x = sc.nextInt();
if(x<0 || x>10){
System.out.println("반드시 1~10 사이의 정수를 입력해야 합니다.");
}else if(x%2==0){
System.out.println("짝수다.");
}else {
System.out.println("홀수다.");
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,19 @@ public static void main(String[] args) {
*
* 계산 예시) BMI = 67 / (1.7 * 1.7)
* */

double weight = 67;
double height = 1.7;
double bmi = weight/(height*height);
System.out.println("BMI = " + bmi);
if(bmi<20){
System.out.println("당신은 저체중 입니다.");
}else if(bmi>=20 && bmi<25){
System.out.println("당신은 정상체중 입니다.");
}else if(bmi>=25 && bmi<30){
System.out.println("당신은 과체중 입니다.");
}else if(bmi>=30){
System.out.println("당신은 비만 입니다.");
}
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.ohgiraffers.section01.conditional.level03.hard;

import java.util.Scanner;

public class Application1 {

public static void main(String[] args) {
Expand All @@ -16,7 +18,26 @@ public static void main(String[] args) {
* -- 출력 예시 --
* 4 + 3 = 7
*/

Scanner sc = new Scanner(System.in);
System.out.print("첫 번째 정수 : ");
int a = sc.nextInt();
sc.nextLine();
System.out.print("두 번째 정수 : ");
int b = sc.nextInt();
sc.nextLine();
System.out.print("연산 기호를 입력하세요 : ");
String op = sc.nextLine();
if(op.equals("+")){
System.out.printf("%d %s %d = %d", a, op, b, (a+b));
}else if(op.equals("-")){
System.out.printf("%d %s %d = %d", a, op, b, (a-b));
}else if(op.equals("*")){
System.out.printf("%d %s %d = %d", a, op, b, (a*b));
}else if(op.equals("/")){
System.out.printf("%d %s %d = %d", a, op, b, (a/b));
}else if(op.equals("%")){
System.out.printf("%d %s %d = %d", a, op, b, (a%b));
}
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.ohgiraffers.section01.conditional.level03.hard;

import java.util.Scanner;

public class Application2 {

public static void main(String[] args) {
Expand All @@ -20,7 +22,21 @@ public static void main(String[] args) {
* -- 출력 예시 --
* 바나나의 가격은 3000원 입니다.
* */

Scanner sc = new Scanner(System.in);
String [] arr = {"사과", "바나나", "복숭아", "키위"};
String [] price = {"1000원", "3000원", "2000원", "5000원"};
System.out.print("과일 이름을 입력하세요 : ");
String order = sc.nextLine();
int check = 0;
for(int i = 0; i<arr.length; i++){
if(arr[i].equals(order)){
System.out.printf("%s의 가격은 %s 입니다.", arr[i], price[i]);
check = 1;
}
}
if(check == 0){
System.out.println("준비된 상품이 없습니다.");
}
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.ohgiraffers.section01.conditional.level04.advanced;

import java.util.Scanner;

public class Application1 {

public static void main(String[] args) {
Expand All @@ -20,7 +22,32 @@ public static void main(String[] args) {
* 영어 점수 미달로 불합격입니다.
* 수학 점수 미달로 불합격입니다.
* */

Scanner sc = new Scanner(System.in);
System.out.print("국어 점수를 입력하세요 : ");
int kor = sc.nextInt();
System.out.print("영어 점수를 입력하세요 : ");
int eng = sc.nextInt();
System.out.print("수학 점수를 입력하세요 : ");
int math = sc.nextInt();
//평균점수구하기
double avg = (double)(kor+eng+math)/3;
//평균점수 체크
if(avg>=60 && kor>=40 && eng>=40 && math>=40){
System.out.println("합격입니다!");
}else if(avg<60) {
System.out.println("평균 점수 미달로 불합격입니다.");
}
//국어 영어 수학 점수 체크
if (kor < 40) {
System.out.println("국어 점수 미달로 불합격입니다.");
}
if (eng < 40) {
System.out.println("영어 점수 미달로 불합격입니다.");
}
if (math < 40) {
System.out.println("수학 점수 미달로 불합격입니다.");
}
}

}


Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.ohgiraffers.section01.conditional.level04.advanced;

import java.util.Scanner;

public class Application2 {

public static void main(String[] args) {
Expand Down Expand Up @@ -36,7 +38,34 @@ public static void main(String[] args) {
* ======================
* 총 급여 : 3200000
* */


Scanner sc = new Scanner(System.in);
System.out.print("월 급여 입력 : ");
int salary = sc.nextInt();
System.out.print("매출액 입력 : ");
int take = sc.nextInt();
int bonus = 0;

System.out.println("======================");
System.out.println("매출액 : " + take);
if(take>=50000000){
bonus = take * 5 / 100;
System.out.println("보너스율 : 5%");
}else if(take>=30000000){
bonus = take * 3 / 100;
System.out.println("보너스율 : 3%");
}else if(take>=10000000){
bonus = take * 1 / 100;
System.out.println("보너스율 : 1%");
}else{
System.out.println("보너스율 : 0%");
}
System.out.println("월급여 : " + salary);
System.out.println("보너스 금액 : " + bonus);
System.out.println("======================");

salary = salary + bonus;
System.out.println("총 급여 : " + salary);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ public static void main(String[] args) {
* -- 출력 예시 --
* 1부터 10까지의 합 : 55
* */

int x = 0;
for(int i = 1; i<=10; i++){
x += i;
}
System.out.println("1부터 10까지의 합 : " + x);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.ohgiraffers.section02.looping_and_branching.level01.basic;

import java.util.Scanner;

public class Application2 {

public static void main(String[] args) {
Expand All @@ -13,7 +15,14 @@ public static void main(String[] args) {
* 1부터 5까지의 합 : 15
*
* */

Scanner sc = new Scanner(System.in);
System.out.print("정수를 입력하세요 : ");
int x = sc.nextInt();
int a = 0;
for(int i = 1; i <= x; i++){
a += i;
}
System.out.printf("1부터 %d까지의 합 : %d", x, a);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.ohgiraffers.section02.looping_and_branching.level01.basic;

import java.util.Scanner;

public class Application3 {

public static void main(String[] args) {
Expand All @@ -12,7 +14,14 @@ public static void main(String[] args) {
* -- 출력 예시 --
* 1부터 10까지 짝수의 합 : 30
* */

Scanner sc = new Scanner(System.in);
System.out.print("정수를 입력하세요 : ");
int x = sc.nextInt();
int a = 0;
for(int i = 0; i <= x; i+=2){
a += i;
}
System.out.printf("1부터 %d까지 짝수의 합 : %d", x, a);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.ohgiraffers.section02.looping_and_branching.level02.normal;

import java.util.Scanner;

public class Application1 {

public static void main(String[] args) {
Expand All @@ -18,7 +20,12 @@ public static void main(String[] args) {
* 3 : l
* 4 : e
* */

Scanner sc = new Scanner(System.in);
System.out.print("문자열을 입력하세요 : ");
String str = sc.nextLine();
for(int i = 0; i<str.length(); i++){
System.out.printf("%d : %s\n", i, str.charAt(i));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ public static void main(String[] args) {
* -- 출력 예시 --
* abcdefghijklmnopqrstuvwxyz
* */

for(char i = 'a'; i<='z'; i++){
System.out.print(i);
}
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.ohgiraffers.section02.looping_and_branching.level02.normal;

import java.util.Scanner;

public class Application3 {

public static void main(String[] args) {
Expand All @@ -12,7 +14,16 @@ public static void main(String[] args) {
* -- 출력 예시 --
* 수박수박수
* */

Scanner sc = new Scanner(System.in);
System.out.print("정수를 입력하세요 : ");
int x = sc.nextInt();
for(int i = 1; i<=x; i++){
if(i%2==0){
System.out.print("박");
}else{
System.out.print("수");
}
}
}

}
Loading