import java.util.Scanner;
public class BookProgram {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int p = 0;
int b = 0;
int t = 0;
System.out.println("책의 가격");
p = scanner.nextInt();
System.out.println("구매 수량");
b = scanner.nextInt();
t = p * b;
System.out.println("총구매가격 : " + t);
}
}
import java.util.Scanner;
public class BookProgram2 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int d = 0;
int p = 0;
int b = 0;
int t = 0;
boolean s = false;
System.out.println("등급을 입력하세요");
d = scanner.nextInt();
System.out.println("가격을 입력하세요");
p = scanner.nextInt();
System.out.println("구매수량을 입력하세요");
b = scanner.nextInt();
t = p * b;
s = d == 1 && t >= 100000;
System.out.println("총구매가격 : " + t);
System.out.println("사은품 여부 : " + s);
}
}
public class IfDemo1 {
public static void main(String[] args) {
int score = 55;
if(score >= 60) {
System.out.println("합격하였습니다.");
} else {
System.out.println("불합격하였습니다.");
}
}
}
public class IfDemo2 {
public static void main(String[] args) {
int score = 40;
if (score >= 90) {
System.out.println("A학점 입니다.");
} else if (score >= 80) {
System.out.println("B학점 입니다.");
} else if (score >= 70) {
System.out.println("C학점 입니다.");
} else if (score >= 60) {
System.out.println("D학점 입니다.");
} else {
System.out.println("F학점 입니다.");
}
}
}
public class IfDemo3 {
public static void main(String[] args) {
int score = 55;
// 60점 이상 합격(합격자중에서 95점 이상 입학금 면제, 그외 입학금 10만원)
if (score >= 60) {
System.out.println("합격입니다.");
if (score >= 95) {
System.out.println("입학금 면제대상입니다.");
} else {
System.out.println("입학금 10만원을 납부하세요.");
}
} else {
System.out.println("불합격입니다.");
}
}
}
import java.util.Scanner;
public class IfDemo4 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// 국어, 영어, 수학점수를 입력받아서
//평균이 70점 이상이면 합격, 그 외는 불합격으로 표시하는 프로그램
int k = 0;
int e = 0;
int m = 0;
int a = 0;
System.out.println("국어 점수 입력");
k = scanner.nextInt();
System.out.println("영어 점수 입력");
e = scanner.nextInt();
System.out.println("수학 점수 입력");
m = scanner.nextInt();
a = (k + e + m) / 3;
String result = "";
if (a >= 60) {
result = "합격";
} else {
result = "불합격";
}
System.out.println("합격여부 : " + result);
/*if(a >= 70) {
System.out.println("합격");
} else {
System.out.println("불합격");
}*/
}
}
import java.util.Scanner;
public class IfDemo5 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// 상품가격, 상품수량을 입력받아서 총구매가격을 표시하고
// 총구매가격이 50만원이상이면 5만원 상품권
// 총구매가격이 30만원이상이면 1만원 상품권
// 그 외는 1시간 무료주차권을 제공하는 프로그램
int p = 0;
int d = 0;
int t = 0;
System.out.println("상품가격");
p = scanner.nextInt();
System.out.println("상품수량");
d = scanner.nextInt();
t = p * d;
System.out.println("총구매가격 : " + t);
String g = "";
if(t >= 500000) {
g = "5";
} else if(t >= 300000) {
g = "1"
} else {
g = "무";
}
System.out.println(g + "를 지급");
/*if(t >= 500000) {
System.out.println("5");
} else if(t >= 300000) {
System.out.println("3");
} else {
System.out.println("무");
}*/
}
}
import java.util.Scanner;
public class IfDemo6 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// 상품가격, 구매수량을 입력받아서 총구매가격을 계산하고
// 50만원 이상 구매시 총구매금액의 5% 할인 totalPrice*5/100
// 30만원 이상 구매시 총구매금액의 2% 할인
// 그 외 할인 없음
//상품가격, 구매수량, 총구매가격, 할인받은 금액, 실제지불금액을 표시하기
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int t = 0;
System.out.println("상품가격");
a = scanner.nextInt();
System.out.println("구매수량");
b = scanner.nextInt();
t = a*b;
System.out.println("총구매가격 : " + t);
if(t >= 500000) {
c = t*5/100;
} else if (t >= 300000) {
c = t*2/100;
}
System.out.println("할인받은금액 : " + c);
d = t - c;
System.out.println("실제지불금액 : " + d);
}
}
import java.util.Scanner;
public class IfDemo7 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// 상품가격, 구매수량, 현재 포인트를 입력받는다.
// 50만원 이상 구매시 총구매금액의 5% 할인 totalPrice*5/100
// 30만원 이상 구매시 총구매금액의 2% 할인
// 그 외 할인 없음
// 현재 포인트가 1만점 이상일 때는 실제지불금액의 0.3%를 포인트로 적립
// 현재 포인트가 5천점 이상일 때는 실제지불금액의 0.2%를 포인트로 적립
// 그 외 0.1%를 포인트로 적립
// 상품가격, 구매수량, 총구매가격, 할인받은 금액, 실제지불금액을 표시
// 적립전 포인트, 포인트적립량, 적립후 포인트
int price = 0;
int amount = 0;
int totalPrice = 0;
int discountPrice = 0;
int payPrice = 0;
int currentPoint = 0;
int point = 0;
int savedPoint = 0;
System.out.println("상품가격");
price = scanner.nextInt();
System.out.println("구매수량");
amount = scanner.nextInt();
System.out.println("현재 포인트");
currentPoint = scanner.nextInt();
totalPrice = price*amount;
if(totalPrice >= 500000) {
discountPrice = totalPrice*5/100;
} else if (totalPrice >= 300000) {
discountPrice = totalPrice*2/100;
}
payPrice = totalPrice - discountPrice;
if(currentPoint >= 10000) {
savedPoint = payPrice*3/1000;
} else if(currentPoint >= 5000)
savedPoint = payPrice*2/1000;
} else {
savedPoint = payPrice*1/1000;
}
point = currentPoint + savedPoint;
System.out.println("상품가격 : " + price);
System.out.println("구매수량 : " + amount);
System.out.println("총구매가격 : " + totalPrice);
System.out.println("할인받은 금액 : " + discountPrice);
System.out.println("실제지불금액 : " + payPrice);
System.out.println("적립전 포인트 : " + currentPoint);
System.out.println("포인트적립량 : " + point);
System.out.println("적립후 포인트 : " + savedPoint);
}
}
public class SwitchDemo1 {
public static void main(String[] args) {
String grade = "골드";
switch (grade) {
case "골드" :
System.out.println("5%가 적립됩니다.");
break;
case "실버" :
System.out.println("3%가 적립됩니다.");
break;
case "브론즈" :
System.out.println("1%가 적립됩니다.");
break;
default :
System.out.println("적립되지 않습니다.");
}
}
}
public class ForDemo1 {
public static void main(String[] args) {
for (int i=1; i<=5; i++) {
System.out.println(i + "번째 실행");
}
}
}
public class ForDemo2 {
public static void main(String[] args) {
int total = 0;
for (int i=1; i<=100; i+=2) {
System.out.println(i);
total = total + i;
}
System.out.println("합계 : " + total);
}
}
import java.util.Scanner;
public class ForDemo3 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
/*
//1부터 입력받은 숫자까지의 합계를 계산하는 프로그램
int total = 0;
int num = 0;
System.out.println("숫자 입력");
num = scanner.nextInt();
for (int i=1; i<=num; i++) {
total += i;
}
System.out.println("합계 : " + total);
*/
// 숫자 두개를 입력받아서 첫번째 숫자부터 두번째 숫자 사이의 합계를 구하는 프로그램
int begin = 0;
int end = 0;
int total = 0;
System.out.println("시작 숫자 입력");
begin = scanner.nextInt();
System.out.println("끝 숫자 입력");
end = scanner.nextInt();
if(begin < end) { // 긍정적인 조건을 if, 부정적인 조건은 else
for (int i=begin; i<=end; i++) {
total += i;
}
System.out.println("합계 : " + total);
} else {
System.out.println("값이 올바르지 않습니다");
}
}
}
public class ForDemo5 {
public static void main(String[] args) {
for (int i=1; i<=10; i++) {
System.out.println(i);
if (i == 6) {
break;
}
}
}
}
public class ForDemo6 {
public static void main(String[] args) {
for (int i=1; i<=10; i++) {
if (i == 6) {
continue;
}
System.out.println(i);
}
}
}
import java.util.Scanner;
public class ForDemo7 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int giftCard = 0;
int totalPrice = 0;
// 여러 개의 상품가격을 입력받아서, 구매금액이 상품권가격을 초과하면
// 가격입력을 중지하고 현재 총 구매금액을 출력
System.out.println("상품권 가격 스캔");
giftCard = scanner.nextInt();
for (;;) {
if(totalPrice <= giftCard) {
int price = 0;
System.out.println("상품을 스캔하세요");
price = scanner.nextInt();
totalPrice = totalPrice + price;
} else {
break;
}
}
System.out.println("구매 금액 : " + totalPrice);
}
}
import java.util.Scanner;
public class ForDemo8 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int dan = 0;
System.out.println("출력할 단을 입력하세요");
dan = scanner.nextInt();
// 구구단 출력
for (int i=1; i<=9; i++) {
System.out.println(dan + " * " + i + " = " + (dan*i));
}
}
}
public class ForDemo9 {
public static void main(String[] args) {
for (int x=1; x<=2; x++) {
//System.out.println("바깥쪽 for문의 수행문");
System.out.println("["+x+"]");
for (int y=1; y<=3; y++)
//System.out.println("안쪽 for문의 수행문");
System.out.println("{"+x+"}{"+y+"}");
}
}
}
}
public class ForDemo10 {
public static void main(String[] args) {
for (int i=1; i<=6; i++) {
int number = (int)(Math.random()*45 + 1); // Math.random() - 0보다 크고 1보다 작은 임의의 실수를 만듦
// 0 < Math.random()*45 < 1 -- 1 < Math.random()*45 + 1 < 46
System.out.println(number);
}
}
}
public class ForDemo11 {
public static void main(String[] args) {
for (int x=1; x<=9; x++) {
for (int i=2; i<=9; i++) {
System.out.print(i + " * " + x + " = " + (i*x) + "\t\t\t");
if (x*i < 10) {
System.out.print(" ");
}
}
System.out.println();
}
}
}
import java.util.Scanner;
public class ForDemo12 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// 임의의 숫자 만들기
int number = (int)(Math.random()*20 + 1);
// 숫자를 입력받아서 임의의 숫자와 일치하는지 알아내기
for (;;) {
// 사용자로부터 숫자를 입력받는다.
// 입력받은 숫자가 number에 들어있는 값보다 크다면 "작다"를 출력하고, 아니면 "크다"를 출력한다
// 입력받은 숫자가 number와 일치하면 반복문을 탈출한다.
System.out.println("숫자를 맞춰보세요");
int inputNumber = scanner.nextInt();
/*if (number > inputNumber) {
System.out.println("크다");
} else if (number < inputNumber) {
System.out.println("작다");
}
if (number == inputNumber) {
System.out.println("정답");
break;
}*/
if (number > inputNumber) {
System.out.println("크다");
} else if (number < inputNumber) {
System.out.println("작다");
} else {
System.out.println("정답");
break;
}
}
System.out.println("임의의 숫자 : " + number);
}
}
public class ForDemo13 {
public static void main(String[] args) {
for (int x=1; x<=5; x++) {
for (int y=1; y<=x; y++) {
System.out.print(x);
}
System.out.println();
}
}
}
public class ForDemo14 {
public static void main(String[] args) {
int c = 0;
for (int x=1; x<=4; x++) {
for (int y=1; y<=x; y++) {
c++;
System.out.print(c);
}
System.out.println();
}
}
}
'자바 > basic' 카테고리의 다른 글
RefDemo2, ArrayDemo9.java (0) | 2019.06.07 |
---|---|
Sample2, VarDemo4, TypeDemo5, CastingDemo3, OpDemo12.java(변수, 자료형, 형변환, 연산자) (0) | 2019.06.07 |