π 2023λ 12μ 14μΌ
[java 8μΌμ°¨]
Deque<Integer> d = new ArrayDeque<>(); d.addFirst(10); d.addLast(20); d.addLast(30); System.out.println(d.pollFirst()); System.out.println(d.pollLast());
public class C1201_Method { public static void main(String[] args) { int sum = 0; for (int i = 1; i<=10; i++){ sum += i; } System.out.println(sum); int total = 0; for (int i = 10; i <= 20; i++) { total += i; } System.out.println(total); // μ€λ³΅λλ μ½λ λ°λ‘ λΉΌκΈ° int sumAcc_total = sumAcc(100,200); System.out.println(sumAcc_total); System.out.println(C1201_Method.sumAcc(1,10)); // λ©μλ κ΅¬μ± μμ : 맀κ°λ³μ, λ°ννμ , μ κ·Όμ μ΄μ, ν΄λμ€ λ©μλ μ¬λΆ(static) } // void = 리ν΄νμ x static int sumAcc(int start, int end){ int total = 0; for (int i = start; i<=end; i++ ){ total += i; } System.out.println(total); return total; } }
public class Bank { public static void main(String[] args) { BankAccout b = new BankAccout("123"); // κ°μ²΄ μμ±, μμ±μ νΈμΆ b.withdraw(1000); b.deposit(10000); b.withdraw(5000); b.deposit(2500); b.withdraw(10000); System.out.println("μκ³ λ :"+b.getBalance()); System.out.println("κ³μ’λ :"+b.getAccount_num()); } } class BankAccout { private static String account_num ; private static long balance = 0; // μμ±μ BankAccout(String str){ account_num = str; } public long getBalance() { return balance; } public String getAccount_num(){ return account_num; } public void deposit(long pay){ balance += pay; System.out.println(pay +"λ₯Ό μκΈν©λλ€."); System.out.println("μμ‘μ :"+ balance +"μ μ λλ€."); } public void withdraw(long pay){ if(balance<pay){ System.out.println("μμ‘μ΄ λΆμ‘±ν©λλ€"); }else{ balance-=pay; System.out.println(pay +"λ₯Ό μΈμΆν©λλ€."); System.out.println("μμ‘μ :"+ balance +"μ μ λλ€."); } } }