일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- Menu
- 메서드
- 어노테이션
- paint
- Android
- oracle
- AWT
- struts2
- 안드로이드
- Eclips
- 국제화
- 메소드
- JavaScript
- 오버로딩
- 기본
- JSP
- 배열
- 에러페이지
- 예외처리
- 생성자
- Java
- HTML
- layout
- mybatis
- Graphic
- 이클립스
- 클래스
- OGNL
- 전화걸기
- Spring
- Today
- Total
목록자바 (201)
note
public class MethodTest03 {//전달인자의 개수가 다른 메서드 오버로딩 //정수형 데이터 3개를 형식 매개변수로 갖는 prn 메서드 정의 void prn(int a, int b, int c){ System.out.println(a + "\t" + b +"\t"+ c); } //정수형 데이터2개를 형식 매개변수로 갖는 prn 메서드 정의 void prn(int a, int b){ System.out.println(a + "\t" + b); } //정수형 데이터 1개를 형식 매개변수로 갖는 prn 메서드 정의 void prn(int a){ System.out.println(a); } public static void main(String[] args){ MethodTest03 mt = n..
public class MethodTest02 {//전달인자의 자료형이 다른 메서드 오버로딩 //int 형 데이터에 대해서 절대값을 구하는 메서드 정의 int abs(int num){ if(num 10 -10의 절대값은 . -> 20 -3.4의 절대값은 . -> 3.4
public class OverloadingTest2 {//메소드 오버로딩2 public void getLength(int n){ //1000 String s = String.valueOf(n); //"1000"으로 바뀜 문자열 //valueOf가 타입을 바꿔서 String으로 바꾼다 getLength(s);//메소드 내에서 또다른 메소드를 호출할 수 있다 } void getLength(float n){//3.14f String s = String.valueOf(n); //"3.14" f는 실제 데이터가 아닌 타입 명시 기에 사라짐 getLength(s); } private int getLength(String str){//"10000" System.out.println("입력한 값의 길이 : "+str..
public class OverloadingTest {//메소드 오버로딩 public void make(int a){ System.out.println("int 형 데이터 : "+a); } public void make(double b){ System.out.println("double 형 데이터 : "+b); } //int 를 double로 바꾸니 충돌이 일어나지 않는다(메소드 오버로딩) public static void main(String[] args){ OverloadingTest ov = new OverloadingTest(); ov.make(2.0); ov.make(10); //기능이 같기 때문에 알아서 자신이 필요한곳에 들어간다 //기능이 같을 경우만 메소드 오버로딩을 쓴다 } } doubl..
public class BasicClass2 { //public : 접근 지정자(접근 제한자) //class : 파일의 종류 //BasicClass2 : 클래스 명 //멤버 필드 int var1; int var2; //생성자 (메소드랑 생김새만 비슷) //객체 생성시 단 한번 호출, 객체 생성시 멤버 변수 초기화 //생략가능 , 생략하면 컴파일러가 default 생성 자동 삽입 public BasicClass2(){ } //멤버 메소드 public int sum(int a, int b){ return a+b; } public static void main(String[] args){ BasicClass2 bc = new BasicClass2(); //생성자 호출 } }
class Car{//클래스로 자동차 //멤버 변수 int speed; int direction; } public class CarTest { public static void main(String[] args){ Car c = new Car(); c.speed = 10; c.direction=1; System.out.println("speed : "+ c.speed); System.out.println("direction : "+ c.direction); System.out.println("Car 객체 : "+c); System.out.println("==================="); Car c2 = new Car(); System.out.println("speed : "+ c2.speed); ..
class Gugudan{//클래스 void로 구구단 만들기 //메소드 호출시 단을 전달해서 전달된 단 만 출력하는 //구구단 만들기 public void makeGugudan(int dan){ for(int i=1; i
class MyMath2{//사칙연산2 public void add(long a, long b){ long result = a+b; System.out.println("add : "+result); } public void minus(long a, long b){ long result = a-b; System.out.println("minus : "+result); } public void multi(long a, long b){ long result = a*b; System.out.println("multi : "+result); } public void divide(double a, double b){ double result = a/b; System.out.println("divide : "+res..
class MyMath{//클래스로 사칙 연산하기 //덧셈 public long add(long a, long b){ return a + b; } //뺄셈 public long minus(long a, long b){ return a - b; } //곱셈 public long multi(long a, long b){ return a * b; } //나눗셈 public double divide(double a , double b){ return a / b; } } public class MyMathTest { public static void main(String[] args){ MyMath my = new MyMath(); long result = my.add(5L,6L); System.out.print..
public class BasicClass {//클래스의 기본 //멤버 필드 int var1;//멤버 변수 String var2; final int COUNT = 3; //상수 //메인 메소드 (클래스 실행시킬 수 있는 진입점) public static void main(String[] args){ BasicClass bc; //객체 선언 bc = new BasicClass(); // 객체생성 (주소) bc.var1 = 100;//멤버 변수를 호출해서 데이터 할당 bc.var2 = "겨울"; //bc.COUNT = 600; 상수는 변경불가능 System.out.println("var1 : "+ bc.var1); System.out.println("var2 : "+ bc.var2); System.out.p..
class Tv2{ //멤버변수 String color; boolean power; int channel; //멤버 메소드 (동작 수행) public void power(){ //TV(on/off) power = !power; //파워의 반전값을 power에 넣기 } public void channelUp(){//채널 up ++channel; } public void channelDown(){//채널 down --channel; } } public class TvTest2 { public static void main(String[] args){ //객체 선언, 생성 Tv2 t = new Tv2(); t.power(); System.out.println("파워 : " + t.power); t.channe..
public class MethodEx { //멤버 메소드 public int sum(int a, int b){ //지역 변수 : 메소드 영역 또는 제어문 영역에서만 호출가능하도록 //선언한 변수 //public : 접근 제한자(지정자) //int : 반환 타입 //sum : 메소드명 //(int a, int b) : 인자 int result = a+b; //연산 return result; //반환값 } public void print(int a, int b){ //void : 반환하는 데이터가 없을때 void명시(빈) int result = a + b; System.out.println("result2 : "+ result); return; //일반적으로 생략 } //메인 메소드 public stati..
class Tv{ //부 클래스에는 public을 붙일 수 없다 //멤버 필드 String color; //색상(컬러/흑백) boolean power; //전원상태(on/off) int channel; } public class TvTest { public static void main(String[] args){ //객체 선언, 객체 생성 Tv t = new Tv(); //Tv : 참조자료형 //t : 참조변수(객체의 주소(reference)저장) //new : 객체 생성를 생성하도록 명명하는 연산자 System.out.println(t.color); System.out.println(t.power); System.out.println(t.channel); //멤버변수에 데이터 할당 t.color = ..
public class Score3 {//2차 배열로 성적 생성 public static void main(String[] args){ java.util.Scanner input=new java.util.Scanner(System.in); String[] subname = {"국어","영어","수학"}; int[][] sub = new int[3][subname.length + 1]; //0첫번째사람1두번째사람2세번째사람 float[] avg = new float[3]; //3명에 대한 각각 평균값 저장 for(int k =0; k < sub.length; k++){ for(int i = 0; i 100); sub[k][sub[k].length - 1] += sub[k][i]; //총점에다가 점수 누적 ..
public class Score2 {//Array로 성적짜기 한사람에 대한 데이터 1차배열 public static void main(String[] args){ java.util.Scanner input=new java.util.Scanner(System.in); String[] subname = {"국어","영어","수학"}; //0국어 1영어 2수학 3총합 int[] sub = new int[subname.length + 1]; float avg = 0.0f; //데이터 입력 부분 for (int i= 0; i < sub.length - 1; i++){ do{ System.out.print(subname[i] + " = "); sub[i] = input.nextInt(); } while (sub[..
public class Score {//2차원 배열로 성적 출력 public static void main(String[] args){ int[][] score = { {100,100,100}, {20,20,20}, {30,30,30}, {40,40,40}, {50,50,50} }; System.out.println("번호 국어 영어 수학 총점 평균"); System.out.println("=================="); for(int i=0; i
public class ArrayTest3 {//2차원 배열생성초기화 public static void main(String[] args){ //2차원 배열 선언, 생성, 초기화(명시적 배열생성) int[][] test = new int[][]{{100,200,300},{400,500,600}}; //{}안에 {},{} 가 두개 들어감 2차원 배열이기 때문에 //2차원 배열선언, 생성, 초기화(암시적 배열생성) int[][] test2 ={{100,200,300},{400,500,600}}; } } 출력이 없음
public class ArrayTest2 {//2차원배열 array public static void main(String[] args){ int test[][]; //2차원 배열 선언 test = new int[2][3]; //2차원 배열생성 //행 열 (개념) //2차원 배열 초기화 test[0][0] = 100; test[0][1] = 200; test[0][2] = 300; test[1][0] = 400; test[1][1] = 500; test[1][2] = 600; //2차원 배열 내용 사용 for(int i=0; i
public class ArrayTest1 {//배열 public static void main(String[] args){ char[] ch; //배열의 선언 ch = new char[4]; //배열 생성 //배열 초기화 ch[0] = 'J'; ch[1] = 'a'; ch[2] = 'v'; ch[3] = 'a'; //배열 내용 출력 for(int i=0;i