* 1은 정수 / 1.1은 실수
정수는 소수점이 없는 수이며, 실수는 소수점이 있는 수이다.
정수
package org.opentutorials.javatutorials.variables; public class IntergerDemo { public static void main(String[] args) { int a; a = 1; System.out.println(a+1); //result:2 a = 2; System.out.println(a+1); //result:3 } }
실수
package org.opentutorials.javatutorials.variables; public class DoubleDemo { public static void main(String[] args) { double a = 1.1; System.out.println(a+1.1); // result: 2.2 a = 2.1; System.out.println(a+1.1); // result: 3.2 } }
문자열
package org.opentutorials.javatutorials.variables; public class StringDemo { public static void main(String[] args) { // String first; // first = "coding"; // String first = "coding"; String a, b; a = "coding"; b = "everybody"; System.out.println(a+ " " +b); //result: coding everybody } }
변수의 효용성
System.out.println(100 + 10); System.out.println((100 + 10) / 10); System.out.println(((100 + 10) / 10) - 10); System.out.println((((100 + 10) / 10) - 10) * 10); // ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ int a = 100; System.out.println(a + 10); System.out.println((a + 10) / 10); System.out.println(((a + 10) / 10) - 10); System.out.println((((a + 10) / 10) - 10) * 10);
중복 & 반복되는 것을 제거함으로 코드의 가독성과 유지보수 용이성이 좋아진다.
추후 개발자로 소프트웨어 동작하는 방법을 바꿔야 될 경우 변수로 정의한 고정적인 부분을 건드리지 않고,
가변적으로 바뀔 수 있는 영역만 수정하면 되기 때문에 로직을 핸들링하는 것이 훨씬 수월해진다.
'Java > 생활코딩' 카테고리의 다른 글
[생활코딩] 주석과 세미콜론 (0) | 2021.12.20 |
---|---|
[생활코딩] 숫자와 문자 (0) | 2021.12.20 |
[Java] 이클립스 기능 정리_기초 (0) | 2021.12.16 |