본문 바로가기

콩's EDUCATION/콩's JAVA_RUN

ArrayList 저장데이터, 데이터 조회 ArrayList 저장데이터, 데이터 조회 import java.util.*; public class ArrayListTest { public static void main(String[] args) { /** * ArrayList 생성 * 100(interger), 3.14(Double), "java", Employeee 객체들 저장 */ ArrayList all = new ArrayList(5); // 5+5+5+..... all.add(100); all.add(3.14); all.add("java"); Employee e1 = new Employee(100, "홍길동", 67000.99); all.add(e1); Employee e2 = new Employee(200, "강감찬", 31000.14).. 더보기
Vector 저장데이터, 총크기, 데이터 조회 Vector 저장데이터, 총 크기, 데이터 조회 import java.util.*; class Employee{ int id; // 사번 String name; // 이름 double pay; // 급여 // 멤버 변수를 초기화해주는 것이 생성자(기본 개념 숙지) public Employee(int id, String name, double pay) { this.id = id; this.name = name; this.pay = pay; } @Override public String toString() { return "Employee [id=" + id + ", name=" + name + ", pay=" + pay + "]"; } } public class VectorTest { public stat.. 더보기
WRAPPER 클래스 Integer WRAPPER 클래스 Integer public class IntegerTest { public static void main(String[] args) { System.out.println("100을 10진수 변환 = " + Integer.parseInt("100")); System.out.println("100을 8진수 변환= " + Integer.parseInt("100", 8)); // int 4byte(8*4=32) 정수; 부호; 1bit/값;31 // -2^31 ~ 2^31-1 // ???? ~ ???? System.out.println("int 최대값 =" + Integer.MAX_VALUE); System.out.println("int 최소값 =" + Integer.MIN_VALUE); S.. 더보기
Math 함수 Math 함수 이용하기 public class MathTest { public static void main(String[] args) { // static final public // 변수이름 ; 소문자 명사 // final 변수 (=상수) 이름 ; 대문자 구성 ; read-only만 가능 System.out.println("원주율= "+Math.PI); System.out.println("자연로그 = "+Math.E); System.out.println("첫번째 난수 = "+(int)((Math.random())*100)); System.out.println("두번째 난수 = "+(int)((Math.random())*100)); System.out.println("-100의 절대값 = "+Math... 더보기
String 메소드 활용 String의 다양한 메소드 활용 // JAVA API ; java.lang - String 메소드 활용 public class StringMethodTest { public static void main(String[] args) { String s1 = "test"; System.out.println((s1+"대문자 변경 : "+s1.toUpperCase())); String s2= "time score test"; //s2 공백 중심 여러 문자열 분리 String[] s2_split = s2.split(" "); System.out.println("s2 공백 중심 여러 문자열 분리"); for(int i=0;i=0 if(s3.contains("java")){ System.out.println("자바.. 더보기
Clone Clone 메소드 사용 class Car implements Cloneable{ String model; String company; public Car(String model, String company) { super(); this.model = model; this.company = company; } public Car() {} @Override public String toString() { return "Car [model=" + model + ", company=" + company + "]"; } public void test() throws CloneNotSupportedException{ // clone 사용 작성 : protected ; 상속클래스 사용 Car copy = (Car)(.. 더보기
toString toString 예제 class Car{ String model; String company; public Car(String model, String company) { super(); this.model = model; this.company = company; } @Override public String toString() { return "Car [model=" + model + ", company=" + company + "]"; } } public class ToStringTest { public static void main(String[] args) { Car c1 = new Car("K7", "현대차"); Car c2 = new Car("아반테", "기아차"); System.out.pr.. 더보기
Java 문제 5 CellPhone클래스 -변수 String model// 핸드폰 모델 번호 double battery;// 남은 배터리 양 -생성자 CellPhone(String model)// 모델 번호를 인자로 받는 생성자 -메서드1 void call(int time)// 통화 시간(분)을 출력하고, 통화 시간에 따라 배터리 양을 감소시킨다. // 감소되는 배터리 양 = 통화시간(분) * 0.5 // 배터리 양은 0보다 작아지지 않는다. // 통화 시간(분)이 0보다 작은 경우에는 IllegalArgumentException(“통화시간입력오류”)을 발생시킨다. - 메서드2 void charge(int time)// 충전한 시간(분)을 출력하고, 충전한 시간에 따라 배터리 양을 증가시킨다. // 충전되는 배터리 양 =.. 더보기
사용자 정의 예외 만들기 사용자 정의 예외 처리 예제 @SuppressWarnings("serial") class DuplicatedException extends Exception{ DuplicatedException(String message){ super(message);//Exception(String) } } class ArrayData{ String[] ary = new String[4]; void setArray(){ ary[0] = "java"; ary[1] = "jsp"; ary[2] = "servlet"; } void addArray(String data) throws DuplicatedException{ if(data.equals(ary[0]) || data.equals(ary[1]) || data.equal.. 더보기
throws 처리 throw 처리 public class ThrowsTest { static void test() throws ClassNotFoundException{ Class.forName("java.lang.Object"); System.out.println(100/0); } public static void main(String[] args) throws ClassNotFoundException { // JVM에 예외를 전달한다. // 예외 메시지를 출력한다. // JVM이 예외 메시지를 출력 대신에 다른 처리를 하고자 한다면 // try-catch를 사용한다. test(); } } 항상동일하게 처리합니다 더보기