본문 바로가기

분류 전체보기853

java.lang패키지와 유용한 클래스(6) 오토박싱 & 언방식(autoboxing & unboxing) JDK 1.5 전에는 기본형과 참조형 간의 연산이 불가능했기 때문에, 래퍼 클래스로 기본형을 객체로 만들어서 연산해야 했다. int i = 5; Integer iObj = new Integer(7); int sum = i + iObj; //에러, 기본형과 참조형 간의 덧셈 불가(JDK 1.5 이전) 그러나 이제는 기본형과 참조형 간의 덧셈이 가능하다. 자바 언어의 규칙이 바뀐 것은 아니고 , 컴파일러가 자동으로 변환하는 코드를 넣어주기 때문이다. 아래의 경우, 컴파일러가 Integer객체를 int타입의 값으로 변환해주는 intValue()를 추가해준다. --컴파일 전의 코드 int i = 5; Integer iObj = new Integer(7.. 2021. 6. 29.
백준 9498 import java.util.Scanner; public class Main9498 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int score = sc.nextInt(); if(score >=90){ System.out.println("A"); }else if(score >= 80){ System.out.println("B"); }else if(score >= 70){ System.out.println("C"); }else if(score >= 60){ System.out.println("D"); }else{ System.out.println("F"); } } } 2021. 6. 29.
백준 8393 import java.util.Scanner; public class Main8393 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int sum=0; for(int i=1; i 2021. 6. 29.
백준 2884 import java.util.Scanner; public class Main2884 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int H = sc.nextInt(); int M = sc.nextInt(); M = M-45; if(M < 0){ M = 60+M; H--; } if(H 2021. 6. 29.
백준 2753 import java.util.Scanner; public class Main2753 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int year = sc.nextInt(); if(year%4 ==0 && year%100 != 0 || year %400 == 0){ System.out.println(1); }else{ System.out.println(0); } } } 윤년의 조건은 년도가 4의 배수이고, 100의 배수가 아니면된다. 또한 400의 배수이면 된다. 이 조건을 성립하게 하기위해 && , || 연산을 사용해 조건문을 걸었다. && 연산은 양쪽 값이 모두 true이어야 true을 반환하고, ||연.. 2021. 6. 29.
백준 2739 import java.util.Scanner; public class Main2739 { public static void main(String[] args) { Scanner sc =new Scanner(System.in); int N = sc.nextInt(); int[] result = new int[9]; for(int i=1; i 2021. 6. 29.