본문 바로가기

22.05.24~22.11.16/5月5

05-31 <Java> : switch문 (랜덤 출력 하기) Switch문은 조건 제어문이다. break가 없는 Switch문을 사용해서 랜덤으로 출력되는 클래스를 만든 것이다. public class P118 { public static void main(String[] args) { int time = (int) (Math.random()*5)+8; System.out.println("[현재시간: " + time + " 시]"); switch(time) { case 8: System.out.println("출근을 합니다."); break; case 9: System.out.println("업무를 합니다."); break; case 10: System.out.println("회의를 합니다."); break; case 11: System.out.println("외.. 2022. 6. 2.
05-30 <Java> : 반복문 <for문> - 구구단, 1부터 100까지의 합 출력하기 public class p123 { public static void main(String[] args) { for(int m=1; m 2022. 6. 2.
05-27 <Java> : 생성자 & 메소드 public class Korean { //필드 String nation = "대한민국"; String 이름; String 주민등록번호; //생성자 /*public Korean(String n, String s) { 이름 = n; 주민등록번호 = s; }*/ public Korean(String 이름, String 주민등록번호) { this.이름 = 이름; this.주민등록번호 = 주민등록번호; } } public class KoreanExam { public static void main(String[] args) { Korean k1 = new Korean("박자바", "220527-1234567"); System.out.println("이름 : " + k1.이름); System.out.println.. 2022. 5. 27.
05-26 <Java> : 증감 연산자 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 32 33 public static void main(String[] args) { int x = 10; int y = 10; int z; System.out.println("------------"); x++; ++x; System.out.println("x=" + x); System.out.println("------------"); y--; --y; System.out.println("y=" + y); System.out.println("------------"); z = x++; System.out.println("z=" + z); System.ou.. 2022. 5. 27.
05-25 <Java> : 글자 입력, 텍스트 위치 배열, byte타입 변수, char타입 변수, 스코어 계산 1. 글자 입력 Hello, welcome to the java world! 1 2 3 public class Hello { public static void main(String[] args) { System.out.print("Hello, welcome to the java world!\n"); 큰따옴표(")로 묶은 텍스트는 문자열 리터럴로 간주한다. 문자열 리터럴을 저장할 수 있는 타입은 String 하나 밖에 없다. 2. 텍스트 위치 배열하기 1 2 3 4 5 6 7 8 9 10 11 public class VariableScopeExample { public static void main(String[] args) { System.out.println("대한민국"); System.out.prin.. 2022. 5. 25.