본문 바로가기

반응형

알고리즘/백준

(111)
[백준] 10926 - ??! 아이디는 알파벳 소문자로만 이루어져 있고, 길이는 50자를 넘지 않는다는 조건이 있다. 나는 이 조건을 정규표현식을 사용하여, matches()가 false 일 경우 다시 입력하도록 하였다. import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); String id, reg; id = sc.nextLine(); reg = "^[a-z][^0-9]{0,50}$"; if(id.matches(reg) == false){ System.out.println("50자 이하의 소문자로 다시 입력하세요."); id = sc.nextLine(); } System.out.p..
[백준] 10869 - 사칙연산 import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int a, b; a = sc.nextInt(); b = sc.nextInt(); while(a 10001){ System.out.println("a는 1이상, b는 10000 이하로 입력해주세요!"); a = sc.nextInt(); b = sc.nextInt(); } System.out.println(a+b); System.out.println(a-b); System.out.println(a*b); System.out.println(a/b); System.out.println(a%b); sc.cl..
[백준] 1008 - A/B import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); double a, b; a = sc.nextDouble(); b = sc.nextDouble(); while(a 10){ System.out.println("a는 0 초과, b는 10미만으로 입력하세요!"); a = sc.nextDouble(); b = sc.nextDouble(); } System.out.println(a/b); sc.close(); } } float가 아닌 double을 사용하여 풀면 된다!
[백준] 10098 - A X B import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int a, b; a = sc.nextInt(); b = sc.nextInt(); while(a 10){ System.out.println("a는 0 초과, b는 10미만으로 입력하세요!"); a = sc.nextInt(); b = sc.nextInt(); } System.out.println(a*b); sc.close(); } } 이전에 했던 A + B, A - B와 비슷한 방식으로 해결하면 된다.
[백준] 1001 - A - B import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int a, b; a = sc.nextInt(); b = sc.nextInt(); if(a 10){ System.out.println("a값은 0 초과, b 값은 10 미만이어야 합니다!"); a = sc.nextInt(); b = sc.nextInt(); } System.out.println(a - b); } } (0 10) 조건을 생각하여 풀었는데 백준 채점 기준은 조건 없이 A - B만 맞으면 되는 것 같다.. 제출하고 나서 생각해보니 if문으로 하면 안된다는..
[백준] 1000 - A + B import java.util.*; 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); } } (0 < A, B < 10) 이라는 조건을 블로그에 올리기 전까지 모르고 있었는데 정답 처리가 되었다. (0 < A, B < 10) 조건을 다시 추가해서 풀어보자면, import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.i..
[백준] 2557 - Hello World (JAVA/ 자바) public class Main{ public static void main(String[] args){ System.out.println("Hello World!"); } } 느낌표를 빼먹고 제출해서 틀렸다. 코드 적는 탭에 문제를 볼 수 있으면 좋을 것 같다...

반응형