전기요금1 = 기본요금 + (사용량 kw당요금)
전기요금2(최종요금) = 전기요금 + 전기요금세율
package pack_CtrlQuiz;
import java.util.Scanner;
public class Charge {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("코드번호를 입력하세요"
+ "(1 - 가정용, 2 - 산업용, 3 - 교육용) : ");
int code = scanner.nextInt();
System.out.print("전기 사용량을 입력하세요(kw) : ");
int used = scanner.nextInt();
scanner.close();
double basic = 0;;
double perKw = 0;;
double taxRate = 0;
double charge = 0;
if (code == 1) {
basic = 1130;
perKw = 127.8;
taxRate = 0.09;
} else if (code == 2){
basic = 660;
perKw = 88.5;
taxRate = 0.08;
} else if (code == 3) {
basic = 370;
perKw = 52.;
taxRate = 0.05;
}
charge = basic + (used*perKw);
double chargeAfterTax = charge + (charge*taxRate);
System.out.printf("전기요금은 %.0f원입니다.", chargeAfterTax);
}
}
package pack_CtrlQuiz;
import java.util.Scanner;
public class Charge2 {
public static void main(String[] args) {
int code;
int used;
double basic = 0;
double perKw = 0;
double charge = 0;
double taxRate = 0;
Scanner scanner = new Scanner(System.in);
System.out.print("코드번호를 입력하세요"
+ "(1 - 가정용, 2 - 산업용, 3 - 교육용) : ");
code = scanner.nextInt();
System.out.print("전기 사용량을 입력하세요(kw) : ");
used = scanner.nextInt();
scanner.close();
switch (code) {
case 1:
basic = 1130;
perKw = 127.8;
taxRate = 0.09;
break;
case 2:
basic = 660;
perKw = 88.5;
taxRate = 0.08;
break;
case 3:
basic = 370;
perKw = 52.;
taxRate = 0.05;
break;
}
charge = basic + (used * perKw);
double finalCharge = charge + (charge*taxRate);
System.out.printf("전기요금은 %.0f원입니다.", finalCharge);
}
}
package pack_Circle;
import java.util.Scanner;
public class Area {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("반지름을 입력하세요 : ");
int radius = scanner.nextInt();
scanner.close();
double area = 3.14 * (Math.pow(radius,2));
System.out.printf("면적 : %.2f", area);
}
}
거듭제곱 => Math.pow(double밑수, double지수);
package pack_CalcSystem;
import java.util.Scanner;
public class Arithmetic {
public static void main(String[] args) {
System.out.println("====<메뉴>====\n1. 덧셈(add)\n2. 뺄셈(sub)"
+ "\n3. 곱셈(mul)\n4. 나눗셈(div)\n============");
Scanner scanner = new Scanner(System.in);
System.out.print("\n원하는 메뉴를 선택하세요 : ");
int code = scanner.nextInt();
System.out.print("\n두 개의 숫자를 입력하세요 : ");
double num1 = scanner.nextDouble();
double num2 = scanner.nextDouble();
scanner.close();
double res = 0;
if (code == 1) {
res = num1 + num2;
}
else if (code == 2) {
res = num1 - num2;
}
else if (code == 3) {
res = num1 * num2;
}
else if (code == 4) {
res = num1 / num2;
}
System.out.printf("결과 값은 %.2f 입니다.", res);
}
}
package pack_Array;
import java.util.Scanner;
public class BigNum {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("임의의 숫자 다섯 개를 입력하세요 : ");
double[] num = new double[5];
for (int i = 0; i < num.length; i++) {
num[i] = scanner.nextDouble();
}
scanner.close();
double min = num[0];
for (int i = 0; i < num.length; i++) {
if (num[i] < min) {
num[i] = min;
}
}
System.out.printf("가장 작은 값 : %.1f", min);
}
}
package pack_Pay;
import java.util.Scanner;
public class Salary {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("급여를 입력해 주세요(단위. 원) : ");
int money = scanner.nextInt();
scanner.close();
double salary = money - (money * 0.033);
System.out.printf("실지급액 : %.0f 원", salary);
}
}
package pack_Conversion;
import java.util.Scanner;
public class Inch {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("센티미터 길이 입력 : ");
int cm = scanner.nextInt();
scanner.close();
double inch = cm / 2.54;
System.out.printf("%d cm %.1f inch", cm, inch);
}
}
package pack_Sum;
import java.util.Scanner;
public class Sum {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("2개의 값을 입력하세요 : ");
int num1 = scanner.nextInt();
int num2 = scanner.nextInt();
scanner.close();
int start = num1;
int end = num2;
int sum = 0;
if (num1 > num2) {
start = num2;
end = num1;
for (int i = start; i <= end; i++) {
sum += i;
}
}
System.out.printf("%d부터 %d까지의 누적 합 : %d",
start, end, sum);
}
}