백준 단계별
[Java] 백준 8393: 합
import java.util.*; public class no8393 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int num = 0; for(int i=1;i
[Java] 백준 10950: A+B-3
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int test = sc.nextInt(); for(int i=0;i
[Java] 백준 2480: 주사위 세개
import java.util.*; public class no2480 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt(); if(a!=b && b!=c && a!=c) { int max; if(a>b) { if(c>a) { //c>a>b max=c; } else { //a max=a; } } else { //b>a if(c>b) { //c>b>a max=c; } else { max=b; } } System.out.println(max*100); } else { if(a==b&&a==c) { //a=..
[Java] 백준 2525: 오븐 시계
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int H = sc.nextInt(); int M = sc.nextInt(); int C = sc.nextInt(); int min = 60 * H + M; min += C; int hour = (min / 60) % 24; int minute = min % 60; System.out.println(hour + " " + minute); } } 시간과 분을 따로 생각하고 풀었다가 조건이 너무 많아져서.. 시간과 분을 모두 분으로 환산하여 문제를 해결하는 방식으로 진행하였다. 환산한 분 ..
[Java] 백준 2884: 알람 시계
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int hour = sc.nextInt(); int minute = sc.nextInt(); if(minute-45
[Java] 백준 2753: 윤년
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int year = sc.nextInt(); if(year%4==0) { if(year%400==0) System.out.print("1"); else if(year%100==0) System.out.print("0"); else System.out.print("1"); } else { System.out.print("0"); } } } 4의 배수이면서 400의 배수일 때 100의 배수일 때 나머지(400의 배수도 아니고 100의 배수도 아닌 경우) 4의 배수가 아닐 때 위와 같은 알고리즘으로 해..
[Java] 백준 9498: 시험 성적
import java.util.*; public class no9498 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int score = sc.nextInt(); if(score89) { System.out.print("A"); } else if(score79) { System.out.print("B"); } else if(score69) { System.out.print("C"); } else if(score59) { System.out.print("D"); } else { System.out.println("F"); } } } if문과 논리연산자 and를 이용하여 문제 해결을 진행하였다.
![[Java] 백준 2588: 곱셈](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2Fl0joU%2FbtrIi7DkaNS%2F1OtSPV35LKMKKt63z7nCjK%2Fimg.png)
[Java] 백준 2588: 곱셈
import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int A, B, C, D, E, F; A = sc.nextInt(); B = sc.nextInt(); C = (A*(B%10)); D = (A*(((B%100)-(B%10))/10)); E = (A*(((B%1000)-(B%100))/100)); F = ((E*100)+(D*10)+C); System.out.println(C); System.out.println(D); System.out.println(E); System.out.println(F); } } (2)에 입력받은 숫자를 각 ..
[Java] 백준 10926: ??!
import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); String a; a = sc.nextLine(); System.out.println(a+"??!"); } } 자바로 문자열을 입력받는 방법으로는 크게 두가지가 있다. next와 nextLine인데, 이 둘의 차이점은 next()는 스페이스(공백) 전까지의 문자열을 반환하고 nextLIne()은 엔터 전까지의 문자열을 반환한다. 따라서 Choi Jebum과 같이 띄어쓰기가 있는 문자열을 입력받을 때는 nextLine을 사용해야 할 것이다.
[Java] 백준 1000번: A+B
import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a, b; a = sc.nextInt(); b = sc.nextInt(); System.out.println(a+b); } } 우선 입력을 받기 위해 Scanner 클래스를 import 해준다. Scanner sc = new Scanner(System.in); 위와 같이 Scanner 객체를 생성해주고 (System.in 은 키보드를 통해 입력받는 자바의 기본적인 언어라고 한다.) 각 변수에 sc.nextInt(); 를 통하여 입력값을 변수에 저장해주었다.