분류 전체보기

백준

[JAVA] 백준 2557번 Hello World

public class Main { public static void main(String[] args) { System.out.println("Hello World!"); } }

백준

[JAVA] 백준 2475번 검증수

import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int a = scanner.nextInt(); int b = scanner.nextInt(); int c = scanner.nextInt(); int d = scanner.nextInt(); int e = scanner.nextInt(); int res = (int) ((Math.pow(a,2)+Math.pow(b,2)+Math.pow(c,2)+Math.pow(d,2)+Math.pow(e,2))%10); System.out.println(res); } } Math.pow로 a..

백준

[JAVA] 백준 2438번 별 찍기 - 1

import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int a = scanner.nextInt(); for (int i = 0; i < a ; i++) { for (int j = 0; j

백준

[JAVA] 백준 2420번 사파리월드

import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); long a = scanner.nextLong(); long b = scanner.nextLong(); System.out.println(Math.abs(a-b)); } } 절대값을 계산해주는 함수 Math.abs() 함수를 이용하여 계산.

백준

[JAVA] 백준 1330번 두 수 비교하기

import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); Integer a = scanner.nextInt(); Integer b = scanner.nextInt(); if (ab) { System.out.println(">"); } else { System.out.println("=="); } } }

백준

[JAVA] 백준 1271번 엄청난 부자2

import java.math.BigInteger; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); BigInteger a = scanner.nextBigInteger(); BigInteger b = scanner.nextBigInteger(); System.out.println(a.divide(b)); System.out.println(a.remainder(b)); } } 문제점 : 10의 1000승까지 출력돼야하는데 int, long 등은 출력하지 못함. 그렇기 때문에 무한한 수를 출력할 수 있는 BigInteger를 사..

백준

[JAVA] 백준 1152번 단어의 개수

import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String a = scanner.nextLine(); if (a.replaceAll(" ","").isEmpty()){ System.out.println("0"); } else { String[] b = a.trim().split(" "); System.out.println(b.length); } } } 문제점 : 공백만 넣었을 때 단어의 개수가 0이 나와야하는데, 공백을 문자로 취급해 단어의 개수가 1로 나온다. if (a.replaceAll(" ","").isEmpty()..

백준

[JAVA] 백준 1008번 A/B

import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); double a = scanner.nextDouble(); double b = scanner.nextDouble(); System.out.println(a/b); } } int는 소수점을 반환하지 않기때문에 double을 씀

DEV장화
'분류 전체보기' 카테고리의 글 목록 (23 Page)