본문 바로가기

java35

JAVA Bank Account(은행계좌 관리) package java_week2; public class Account { String id, pw; int balance; public Account() {} public Account (String id, String pw, int balance){ this.id = id; this.balance = balance; this.pw = pw; } public void changePw(String pw){ this.pw = pw; } public int getBalance(){ return balance; } public int Deposit(int value){ balance = balance + value; return balance; } public int Withdraw(int value){ i.. 2015. 10. 29.
JAVA [배열+객체] 저자와 책제목 입력받아 객체생성 및 출력 import java.util.Scanner; class Book01 { String title, author; public Book01(String title, String author) { // 생성자 this.title = title; this.author = author; } } public class BookArray { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); Book01 [] book = new Book01[2]; // Book 배열 선언 for(int i=0; i 2015. 10. 28.
JAVA 대소문자 변환하기 public class ArrayPassing { static void replaceSpace(char a[]) { // 배열 a의 공백문자를 ','로 변경 for(int i = 0; i = 'a' && a[i]= 'A' && a[i] 2015. 10. 28.
JAVA 로또 package java_week1; import java.util.Random; public class Lotto{ public static final int LOTTO_NUM_CNT=6;// 클래스변수, 상수 public int[] generateLottoNumbers(){ int[] nums = new int[LOTTO_NUM_CNT]; Random r = new Random(); nums[0]= r.nextInt(45); int cnt =1; while(cnt 2015. 10. 28.
JAVA string과 string buffer 의 차이점 문자열을 비교할때는 되도록 equals 을 사용하는 것이 좋다 package java_week2; public class StringTest { public static void main(String[] args) { String a = "한국"; String b = "한국"; StringBuffer c = new StringBuffer("한국"); StringBuffer d = new StringBuffer("한국"); if(a==b) System.out.println("a and b is same1"); if(a.equals(b)) System.out.println("a and b is same2"); if(c==d) System.out.println("c and d is same1"); if(c.t.. 2015. 10. 27.
JAVA Bubble Sort package java_week2; public class C1 { public void BubbleSort(C2 p){ int j, tmp, flag; do{ flag = 0; for (j = 0; j p.Array01[j+1]){ tmp = p.Array01[j]; p.Array01[j] = p.Array01[j+1]; p.Array01[j+1] = tmp; flag = 1; } } }while(flag==1); } public boolean BinarySearch(C2 p, int iFind) { int first, last, check; first = 0; last = p.Count-1; do{ check = (first+last)/2; if(p.Array01[check]==iFind) retur.. 2015. 10. 27.