실수형 변수 float, double는 Java에서 소수점 단위의 숫자를 표현하고 할 때 사용합니다. 실수형 변수의 자료형 크기는 아래와 같습니다. float < double float double 4 byte 8 byte 각 변수들의 초기값은 아래와 같은 형태로 입력하여 코드를 작성합니다. public class RealVariablesTest { public static void main(String[] args) { float a = 3.4f; // float 자료형은 뒤에 '대문자 F' 또는 '소문자 f'를 반드시 붙여야 한다. double b = 9.9; // double는 뒤에 d를 생략할 수 있다. System.out.println("a : " + a); System.out.println("..
public class Float74 { public static void main(String[] args) { float var1 = (12_345.01 >= 123_45.00) ? 12_456 : 124_56.02f; float var2 = var1 + 1024; System.out.print(var2); } } What is the result? A. An exception is thrown at runtime. B. Compilation fails. C. 13480.0 D. 13480.02 정답: C 결과: 13480.0 해설: (참고로 숫자에 underscore에 관한 설명은 이전글에 있다.) 12345.01은 12345.00 보다 크니 변수 var1에는 12456이 들어간다. 12456+10..
숫자에 underbar가 있는것을 보았다. 이게 뭐지.. 하고 찾아보니 아래와 같았다. Oracle Java docs: Underscores in Numeric Literals 자바 8 인 액션을 보다가 숫자와 _(언더스코어)를 섞어서 쓰는 것을 처음 보았다. int a = 10_000_000; 이런 식인 것이다 자바7 이후 버전부터 _는 숫자 리터럴의 어디에도 등장할 수 있다. 이로 인해 숫자를 끊어 읽을 수 있게 되어 가독성을 향상 시킬 수 있다. 예를들어 int myMoneyWon = 180000000라고 할 때, 한번에 얼마인지 파악하기 힘들다. 하지만 int myMoneyWon = 180_000_000라고쓴다면 (한국인의 경우) 몇 원인지 파악하기 쉽다. 하지만 마음대로 숫자와 섞어 쓸수는 없다..
public class Class75 { public static int stVar = 100; public int var = 200; public String toString() { return var + ":" + stVar; } public static void main(String[] args) { Class75 t1 = new Class75(); t1.var = 300; System.out.println(t1); Class75 t2 = new Class75(); t2.stVar=300; System.out.println(t2); } } What is the result? A. 300:300 200:300 B. 300:100 200:300 C. 300:0 0:300 D. 200:300 200:30..
Object 이란 모든 클래스의 가장 최상위 클래스인 "Object" 클래스 JAVA에 제공하는 모든 클래스들의 계층 구조로 되어있고, 그 최상위로 올라가면 "Object"이라는 클래스가 존재한다. 우리가 일반적으로 생성하는 클래스도 "extends"로 직접 상속하지는 않지만 자바 컴파일러는 일반 클래스를 "Object"하위 클래스로 자동 설정하게 되어 있습니다. 즉, 자바 라이브러리나 유저가 만든 모든 클래스는 "Object" 클래스를 부모클래스로 상속 받아서 사용 하게 됩니다. toString() 메소드란 "Object"클래스가 가진 메소드 중 "toString"메소드가 있습니다. 물론 "Object" 클래스의 모든 메소드는 모든 클래스가 사용이 가능합니다. "toString" 메서드는 객체가 가지고..
class C2 { public void displayC2() { System.out.print("C2"); } } interface I { public void displayI(); } class C1 extends C2 implements I { public void displayI() { System.out.print("C1"); } } public class Extend76 { public static void main(String[] args) { C2 obj1=new C1(); I obj2=new C1(); C2 s = obj2; I t=obj1; t.displayI(); s.displayC2(); } } What is the result? A. C2C2 B. C1C2 C. C1C1 D. Co..
public class Switch78 { public static void main(String[] args) { int wd=0; String days[]= {"sun","mon","wed","sat"}; for(String s:days) { switch(s) { case "sat": case "sun": wd-=1; break; case "mon": wd++; case "wed": wd+=2; } } System.out.println(wd); } } What is the result? A. 3 B. 4 C. -1 D. Compilation fails. 정답: A 결과: 3 해설: 아래처럼 찍어보면 이해가 쉽다. switch case를 쓸때 주의할 점이 break가 없는 case에서는 아래 case가..
아 switch case는 if else 처럼 잘 쓰지 않아서 가끔 볼때마다 헷갈린다.. break가 없을 경우 case 아래를 무조건 실행하는게 좀 이해가 안간다... 암튼.. switch문은 어떤 변수의 값에 따라서 문장을 실행할 수 있도록 하는 제어문이다. switch문에서 사용하는 키워드는 switch, case, default, break 이다. switch문 switch(변수){ case 값1 : 실행문; break; case 값2 : 실행문; break; default; } int value = 1; switch(value){ case 1: System.out.println("1"); break; case 2: System.out.println("2"); break; case 3 : Syst..
public class Array84 { public static void main(String[] args) { int array[]= {10,20,30,40,50}; int x=array.length; /* line n1 */ } } A. while(x>0) { x--; System.out.print(array[x]); } B. do { x--; System.out.print(array[x]); }while(x>=0); C. while(x>=0) { System.out.print(array[x]); x--; } D. do { System.out.print(array[x]); --x; }while(x>=0); E. while(x>0) { System.out.print(array[--x]); } Whic..
class Student{ String name; public Student(String name) { this.name=name; } } public class Array86 { public static void main(String[] args) { Student[] students = new Student[3]; students[1]=new Student("Richard"); students[2]=new Student("Donald"); for (Student s : students) { System.out.println(""+s.name); } } } What is the result? A. null Richard Donald B. Richard Donald C. Compilation fails...
- Total
- Today
- Yesterday
- C언어
- ocpjp
- 파이썬
- EC
- KG
- 오라클
- 문자열
- 포인터
- xe addon
- XE
- webix
- 파싱
- Python
- 인포믹스
- php
- C
- esql
- ocajp
- 자바
- xe애드온
- 이클립스
- JDBC
- ocjap
- 자바 셀레니움
- XE3
- 자바 smtp
- 프로씨
- proc
- MySQL
- 스크래핑
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |