본문 바로가기

전체 글

(141)
이클립스 단축어 · sysout + ctrl + space bar : System.out.println(); · 전체 드래그 + ctrl + / : 블록한 부분 전체 주석 · alt + 화살표 방향키 : 해당 부분 위치 변경 가능 · ctrl + shift + o : 빠른 import
이클립스 설치
switch 조건문, java.util.Calendar public class Condition{ public static void main(String []args){ java.util.Calendar c; c = java.util.Calendar.getInstance(); // 현재 날짜 객체 int month = c.get(java.util.Calendar.MONTH); //월: 1월인 경우 0, 2월인 경우 1반환 System.out.println(month); // 6 switch(month) { // () 자리에 byte, short, int, char, String만 올 수 있음 case 0: case 1: case 2: case 3: case 4: case 5: System.out.println("현재" + (month + 1)+ "월은 상반기..
switch 조건문 public class Condition{ public static void main(String []args){ int a = 3; switch(a%2){ case 1: System.out.println("홀수"); break; case 0: System.out.println("짝수"); break; } ------------------------------------------------------- int year= 2023; int mod = year%12; switch(mod){ case 0: System.out.println("원숭이띠"); break; case 1: System.out.println("닭띠"); break; default : // if의 else와 같은 의미 System.ou..
if 조건문, java.util.Calendar public class Condition{ public static void main(String []args){ java.util.Calendar c; c = java.util.Calendar.getInstance(); // 현재 날짜 객체 int month = c.get(java.util.Calendar.MONTH); //월: 1월인 경우 0, 2월인 경우 1반환 System.out.println(month); // 6 if(month
if 조건문, float public class Condition{ public static void main(String []args){ int koScore = 70; int engScore = 60; int mathScore = 84; int totalScore = koScore + engScore + mathScore; // 총점 // float avg = totalScore / 3; // 정수/정수라서 71.3인데 71.0 이 나옴 float avg = (float)totalScore / 3; // 평균 totalScore/3.0F System.out.println(avg); // 71.333336 // 평균값이 90점 이상이면 "A등급"을 출력, // 80점 이상이면 "B등급"을 출력, // 70점 이상이면 "C등급"..
if 조건문, java.util.Scanner public class Condition{ public static void main(String []args){ // int year = 2023; System.out.print("출생년도를 입력하세요:"); java.util.Scanner sc = new java.util.Scanner(System.in); int year = sc.nextInt(); // 키보드로부터 숫자 값 입력받는다 System.out.println(year + "년도에 해당하는 동물을 출력하시오"); //년도를 12로 나눈 나머지값이 0이면 원숭이, 1이면 닭, 2이면 개, 3이면 돼지, // 4이면 쥐, 5이면 소, 6이면 호랑이, 7이면 토끼, // 8이면 용, 9이면 뱀, 10이면 말, 11이면 양 int mod = ye..
if 조건문, Math.random() 함수 public class Condition{ public static void main(String []args){ //난수발생 //int a = 4; int a = (int)(Math.random() * 100); //난수를 발생시켜줌 그 값의 범위는 실수값 0.0 강제로 int로 바꿔서 0