📖 값의 교환(swap)
package work01;
import java.util.Scanner;
public class MainClass {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x, y;
System.out.print("x = ");
x = sc.nextInt();
System.out.print("y = ");
y = sc.nextInt();
int temp;
temp = x;
x = y;
y = temp;
System.out.println("x = " + x);
System.out.println("y = " + y);
}
}
📖 거스름돈
package work02;
import java.util.Scanner;
public class MainClass {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int payment;
int due;
int change;
System.out.print("지불할 금액 >> ");
payment = sc.nextInt();
System.out.print("낸 금액 >> ");
due = sc.nextInt();
change = due - payment;
System.out.println("거스름 돈 >> " + change);
int tenThousand = change / 10000;
int fiveThousand = (change % 10000) / 5000;
int thousand = (change % 5000) / 1000;
int fiveHundred = (change % 1000) / 500;
int hundred = (change % 500) / 100;
int fifty = (change % 100) / 50;
int ten = (change % 50) / 10;
System.out.println("10000원 : " + tenThousand + "장");
System.out.println("5000원 : " + fiveThousand + "장");
System.out.println("1000원 : " + thousand + "장");
System.out.println("500원 : " + fiveHundred + "개");
System.out.println("100원 : " + hundred + "개");
System.out.println("50원 : " + fifty + "개");
System.out.println("10원 : " + ten + "개");
}
}