public class Grading public static void mainString args
public class Grading{ public static void main(String[] args) { int answer[][] = { { 1, 3, 2, 4, 3, 1, 4, 2, 2, 1 }, { 3, 2, 4, 2, 2, 1, 1, 3, 4, 1 }, { 2, 4, 3, 2, 1, 3, 3, 4 }, { 2, 3, 3, 1, 1, 3, 2, 2, 4, 4 }, { 3, 1, 1, 2, 4, 1, 2, 3, 1, 3 }}; for ( int i = 0 ; i < answer. length ; i++) { if ( args. length != 10 ) { System. out. println("정답의 개수가 맞지 않습니다"); return; } int score = 0; for (int j = 0 ; j < answer[i]. length ; j++ ) { if (answer[i][j] == Integer. parse. Int(args[j])) score++; } System. out. println("학생 " + ( i + 1 ) + "의 점수 : " + score + "점" ); } } }
class A { // 더하기와 뺄셈을 수행하는 클래스 생성 private int result 1; public int add(int x, int y) { result 1 = x + y; return result 1; } public int subtraction(int x, int y) { result 1 = x - y; return result 1; } } class B extends A { // 곱하기와 나누기를 수행하는 클래스를 생성하고 상위 클래스로 A를 지정 private int result 2; public int multi(int x, int y) { result 2 = x * y; return result 2; } public int divide(int x, int y) { result 2 = x / y; return result 2; } }
class Test. AB public static void main(String args[]) { int temp; B objectb = new B(); // 클래스 B로부터 객체를 생성 temp = objectb. add(20, 10); // 덧셈 수행 System. out. println( add 수행결과 + temp); temp = objectb. subtraction(20, 10); // 뺄셈 수행 System. out. println( subtraction 수행결과 + temp); temp = objectb. multi(20, 10); // 곱셈수행 System. out. println( multi 수행결과 + temp); temp = objectb. divide(20, 10); // 나눗셈 수행 System. out. println( divide 수행결과 + temp); } }
[문제 3] 다음 프로그램의 출력 결과를 쓰시오. class Static{ public int a = 20 ; private int b = 5; static int c ; } class Static. Test { public static void main(String args[]) { int a = 10; Static. c = a; Static st = new Static(); System. out. println("클래스 변수 : " + ( Static. c)++ ); // 클래스 명으로 접근 System. out. println("클래스 변수 : " + st. c ); // 객체명으로 접근 System. out. println("변수 a : " + a ); // 메소드 내의 변수 a System. out. println("변수 a : " + st. a); // 객체참조변수 a } }
class Simple. Circle { int radius; static final double PI = 3. 14159; } public class Simple. Circle. Test { public static void main(String args[]) { Simple. Circle circle = new Simple. Circle(); circle. radius = Integer. parse. Int(args[0]); System. out. println( "원의 반지름은 : " + circle. radius ); System. out. println("원의 넓이는 : " +circle. radius * circle. radius*Simple. Circle. PI ); } } C: >java Simple. Circle. Test 4 원의 반지름은 : 4 원의 넓이는 : 50. 26544
[문제 5] 다음 프로그램의 출력 결과를 쓰시오. class Ct{ public Ct() { System. out. println( "매개변수 public Ct(int a) { System. out. println( "매개변수 public Ct(double a) { System. out. println( "매개변수 public Ct(int a, double b) { System. out. println( "매개변수 } class Ct. Overloading { public static void main(String args[]) { Ct cto = new Ct( ); cto = new Ct( 4, 4. 15 ); cto = new Ct( 6. 0 ); cto = new Ct( 3, 7 ); } } 없음" ); } int a" ); } double a" ); } int a, double b" ); }
매개변수 매개변수 없음 int a, double b double a int a, double b
class Max { public int test(int num 1, int num 2){ int result; if ( num 1 > num 2 ) result = num 1; else result = num 2; return result; } public double test(double num 1, double num 2) { double result 1; if ( num 1 > num 2 ) result 1 = num 1; else result 1 = num 2; return result 1; } } public class Max. Test 1 { public static void main(String args[]) { Max mt = new Max(); int r = mt. test(4, 6); double r 1 = mt. test(4. 2, 6. 1); System. out. println("두 정수중 큰 값은 " + r); System. out. println("두 실수중 큰 값은" + r 1); } }
[문제 7] 다음 프로그램의 출력 결과를 쓰시오. class C 1 { int a=100; static String b = "파이팅 자바"; } class C 2 extends C 1 { String b; String x="쉬운자바"; } public class In. Test 1{ public static void main(String args[]) { C 2 o = new C 2(); System. out. println(o. x); System. out. println(o. b); System. out. println(o. a); System. out. println(C 1. b); } }
[문제 8] 다음 프로그램의 출력 결과를 쓰시오. class C 1 { protected int a = 50; private int b = 100; static String x = "파이팅 자바"; void write() { System. out. println(x); System. out. println(a); System. out. println(b); } } class C 2 extends C 1 { String b = "어려운자바"; String x = "쉬운자바"; void write() { System. out. println(x); System. out. println(a); System. out. println(b); super. write(); }} public class Super. Test 2 { public static void main(String args[]) { C 2 o = new C 2(); o. write(); } }
- Slides: 17