- kinds of print
System.out.println() // 1 line print System.out.print() // print in a row
- data types
- string : λ¬Έμμ΄ / char : λ¬Έμνλ μμ€ν€ μ½λ
- λͺ¨λ μ μ μ€μλ 보μνκΈ°λ² λ°λ¦ (MAX +1 = MIN)
int x = 100; double pi = 3.14; char ch = 'a'; String str = "abc";
types | 1byte | 2byte | 4byte | 8byte |
---|---|---|---|---|
λ Όλ¦¬ν | boolean | :-: | -- | -- |
λ¬Έμν | -- | char | -- | -- |
μ μν | byte | short | int | long |
μ€μν | -- | :-: | float | double |
- μμ νκΈ°λ²
CμΈμ΄μμλ constantλ‘ νκΈ°νμ§λ§,
JAVAμμλ μ μΈ μμ finalμ λΆμ¬μ μ¬μ©final int ONE_HUNDRED =100; //constantλ λ κ·Έλ λ―μ΄ μ΄νμ κ° λ³κ²½ λΆκ° // + λλ¬Έμλ‘ μ°λκ² μ묡μ λ£°
- printμ νΉμ΄ν λ°©μλ€
System.out.printf("d=%14.10f%n", d); //μ΄ 14μλ¦¬λ‘ νν + 10μμ§λ μμμ μλ μ리μ System.out.printf("[%s]%n", url); // %nμ enter μν System.out.printf("[%20s]%n", url); //stringμ 20μ리μ μμ±(μ€λ₯Έμ λ ¬) System.out.printf("[%-20s]%n", url); // - λΆμ΄λ©΄ μΌμͺ½ μ λ ¬ System.out.printf("[%.8s]%n", url); // .8μ stringμ μΌμͺ½μμ 8μ리κΉμ§λ§ νμ
- scan function
- library μΆκ°
- scan class functionλ λ€μν¨
import java.util.Scanner; //scanner library import class Ex2_10 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); // scanner class object generation System.out.print("λμ리 μ μ μ λ ₯νμΈμ: "); String input = scanner.nextLine(); //nextint, nextfloastμ νμ©ν΄μ μλ£ν λ³νμ λ¨μΆκ°λ₯νλ€. //μλλ©΄ Integar.parseInt(num)κ°μ΄ μμ±ν΄μΌλ¨ int num = Integer.parseInt(input); System.out.println("μ λ ₯κ° :"+input); System.out.printf("num=%d%n", num); } }
- μ°μ μ°μ°μ / λμ μ°μ°μ μ μλνλ³ν
- μ°μ μ°μ¬μ
μλνλ³ν μΌμ΄λ¨ -> λ λ°μ΄ν°λ²μκ° ν° μͺ½μΌλ‘- λμ μ°μ°μ
(πννκ°λ₯ν μ«μλ³΄λ€ ν΄ λ,) μλνλ³ν X
-> compile error λ°μ(imcompariable ~)watch out!!!class Ex3_8 { public static void main(String[] args) { byte a = 10; byte b = 30; byte c = (byte)(a * b); //μλ νλ³ν System.out.println(c); } }
int a = 1_000_000; int b = 2_000_000; long c = a * b; //μ΄λ μ΄λ―Έ μ°μ°μ μ€λ²νλ‘μ°λ intλ‘ μ μ₯λ¨(μμ) //λ°λΌμ κ°μ μμμΈλ° longμ λμ λ λλ§ longνμμΌλ‘ λμ λ¨ System.out.println(c);
- JAVAμλ String obejct comparator operatorκ° μλ€!
String str2 = new String("abc"); str1.equals("abc") str2.equals("abc") str2.equalsIgnoreCase("ABC")
- λμ μ°μ°μ μλ μμ
x = y= 3 μμ
- y=3 λμ
- x=y μ€ν
- bit operator (λ³΅ν© λμ μ°μ°μ version)
int i =3; i &= 7; //AND gate i |= 7; //OR gate i ^= 4; //XOR gate System.out.println(i);
exponential operates with shift operator(>> or <<)
- % opearator
λλ¨Έμ§ μ°μ¬μλ‘μ floatνμμλ μ μ© κ°λ₯double j = 6.43; double k = 4.23; System.out.println(j % k); //μ€μμλ μ μ©κ°λ₯(2.199999993)