*** 검색어: java, class, 클래스, 생성자, this(), 오류, 에러, 유의, 주의, 주의사항, 유의사항 [출처] 열혈강의 Java Programming / (주)프리렉 / 김승현 저 / P255 this() 생성자는 반드시 생성자의 가장 위쪽에 위치해야 합니다. 아래와 같이 this(); 생성자의 위쪽에 단순 println 문이 와도 에러 처리됩니다. // this(); 문보다 다른 내용이 앞쪽에 있으면 오류입니다. myClass(int x){ System.out.println("this() 보다 먼저 다른 것이 있으면 에러"); this(); a = x; }
*** 검색어: JAVA, class, 클래스, 예제 Ex01.java public class Ex01 { int a; double b; Ex01() { a = 100; b = 100.0; } Ex01(int x) { a = x; b = 100.0; } Ex01(int x, double y) { a = x; b = y; } public void disp(){ System.out.println("a = " + a); System.out.println("b = " + b); } } Ex02.java public class Ex02 { public static void main(String[] ar) { Ex01 kor = new Ex01(); Ex01 kor1 = new Ex01(10); Ex01 kor2 ..
*** 검색어: nabiro, java, 배열, 성적표 [출처] (주)프리렉, 열혈강의 JAVA Programming, 김승현 저 // 2차원 배열 예제, 석차 추가한 성적표 예제 import java.io.*; public class P228 { public static void main(String[] ar) throws IOException{ BufferedReader in = new BufferedReader( new InputStreamReader(System.in)); String[] subname = {"국어", "영어", "수학"}; int[][] sub = new int[3][subname.length + 1]; // 1번째 배열=> 0:첫번째 사람, 1:두 번째 사람, 2:세 번째 사람..
*** 검색어: nabiro, java, Calendar, 주민등록번호 [출처] (주)프리렉, 열혈강의 JAVA Programming, 김승현 저 import java.io.*; import java.util.*; public class P221 { public static void main(String[] ar) throws IOException{ BufferedReader in = new BufferedReader( new InputStreamReader(System.in)); String name = ""; int[] jumin = new int[14]; boolean right = false; System.out.print("이름 = "); name = in.readLine(); do{ right..
*** 검색어: nabiro, JAVA, 배열 [출처] (주)프리렉, 열혈강의 JAVA Programming, 김승현 저 import java.io.*; public class P219 { public static void main(String[] ar) throws IOException { BufferedReader in = new BufferedReader( new InputStreamReader(System.in)); String[] jumsuname = {"국어", "영어", "수학"}; int[] jumsu = new int[jumsuname.length + 1]; // 0:국어, 1:영어, 2:수학, 3:종합 float avg = 0.0f; for(int i=0; i < jumsu.length..
*** 검색어: nabiro, JAVA, 배열, 초기화 int[] i = { 1, 2, 3 }; // 올바른 표현, int[3] = { 1, 2, 3 }; 이렇게 배열 크기를 직접 지정해주면 오류 난다. int[] j = new int[3]; // 올바른 표현, 배열명 = new 자료형[개수] ; 선언과 별개로 초기화 가능 int[] k = new int[] { 10, 20 }; // 올바른 표현, 선언과 동시에 초기화 가능 float ff[] = new float[]{ 1.0f, 2.0f, 3.0f }; // 올바른 표현, new float[3] { 1.0f, 2.0f, 3.0f } 오류날까?????
*** 검색어: nabiro, JAVA, eclipse, 매개변수, 변수, 인자 Run > Run Configuration > Arguments 탭 입력하는 매개변수 란에 공백을 기준으로 매개변수를 입력하면 됩니다.
*** 검색어: nabiro, java, do, while, example, sample, 예제 // do~while문 예제 import java.io.*; public class P179 { public static void main(String[] ar) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int a=0, b=0, c=0, total=0; char point=0; float avg=0.0f; do { System.out.print("a="); a=Integer.parseInt(in.readLine()); } while (a 100); do { Syst..
*** 검색어: nabiro, java, while, 예제, sample // while문 예제입니다 import java.io.*; public class Test { public static void main(String[] ar) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int i = 0; while(true){ System.out.print("Input number:"); i = Integer.parseInt(in.readLine()); if(i > 10){ break;// while 문을 탈출 } else if (i < 5) { continue;// 아래의 라인은 실행..
*** 검색어: JAVA, java, switch, case, 예제 // switch ~ case 문을 조금 복잡하게 썼습니다. // 그냥 참조용으로 쓴 것이므로 이렇게 코딩할 필요는 없습니다. // import java.io.*; public class P158 { public static void main(String[] ar) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int i = 0; System.out.print("숫자를 입력하세요 : "); i = Integer.parseInt(in.readLine()); switch(i%4){ case 1: case 2: case ..
*** 검색어: nabiro, JAVA, if~else,if~else if, 조건문, 문자열 입력, input, 정수 import java.io.*; public class Test { public static void main(String[] ar) throws IOException { BufferedReader in = new BufferedReader (new InputStreamReader(System.in)); int inputNum = 0; System.out.print("점수를 입력하세요 = "); inputNum = Integer.parseInt(in.readLine()); if(inputNum >= 90) { System.out.println(" 수 "); } else if(inputNu..
1. java test.class 이렇게 실행 명령어 내리면 에러 난다. 확장자 .class 빼라 --> java test 2. int a = 10; int b = 20; System.out.println(a + b);// 이건 결과가 30이 나온다. 만일 1020 이라는 // 문자열 처럼 나오게 하고 싶으면 // 아래처럼 하면 된다. System.out.println("" + a + b); // 문자열은 그 어떤 것과 연산이 되어도 문자열이 // 되어 버리는 성질이 있다. // [출처] 자바 기초 프로그래밍 // (주)프리렉 | 김승현 p96 char ca = 'A'; char cb = 'B'; System.out.println(ca); // A 표시 System.out.println(cb); // B..