본문 바로가기

Java5

[Java] Practice - using method - emirp problem A emirp (prime spelled backward) is a non-palindromic prime number whose reversal is also a prime. - For example, 17 is a prime and 71 is a prime, so 17 and 71 are emirps. Write a program that displays the first 120 emirps. Display 10 numbers per line, separated by exactly one space You must re-use the Practice #1 methods for Practice #2. emirp이란 '수소'로, 17같이 17도 소수고 71도 소수인 수의 집합을 말한다. 한 자리수는 제외.. 2023. 3. 16.
[Java] BAEKJOON 1259 팰린드롬수 https://www.acmicpc.net/problem/1259 1259번: 팰린드롬수 입력은 여러 개의 테스트 케이스로 이루어져 있으며, 각 줄마다 1 이상 99999 이하의 정수가 주어진다. 입력의 마지막 줄에는 0이 주어지며, 이 줄은 문제에 포함되지 않는다. www.acmicpc.net 이쪽 업계에선 엄청 유명한 문제다. 재귀로 푸는 팰린드롬 문제가 많기 때문. 그런데 오늘 문제는 단순해서 그냥 method 몇 번 쓰면 풀린다. method는 숫자를 뒤집는 reverse() 함수와 팰린드롬 수가 맞는지 확인하는 isPalindrome()함수로 구성된다. import java.util.Scanner; public class Main { public static void main(String[] a.. 2023. 3. 16.
[Java] 가위바위보 게임 practice A program that plays the scissor-rock-paper game. A program randomly generates a number 0, 1, or 2 representing scissors, rock, and paper. The program prompts the user to enter a number 0, 1, or 2 and displays a message indicating whether the user or the computer wins, loses, or draws. Let the user continuously play until either the user or the computer wins two times more than their opponent (e.. 2023. 3. 9.
Java error in BOj public class Main { public static void main(String[] args) { } } 위와 같은 형식을 따르지 않고 임의로 class 이름을 변경하는 실수를 하면 error가 뜬다. 이외에 몇가지 에러 요소에 대해 알아보자. 1. public static void main(String[] args)에서 void 대신 int 나 double등 다른 data type으로 작성한 경우 런타임 에러가 발생한다. 2. public static void main(String[] args)에서 static 이 빠지면 런타임 에러가 발생한다. 3. public static void main(String[] args)에서 main이 아닐 경우 에러가 발생한다. package를 사용하면 ma.. 2023. 3. 2.
[Java]BAEKJOON 1002번 터렛 https://www.acmicpc.net/problem/1002 1002번: 터렛 각 테스트 케이스마다 류재명이 있을 수 있는 위치의 수를 출력한다. 만약 류재명이 있을 수 있는 위치의 개수가 무한대일 경우에는 -1을 출력한다. www.acmicpc.net 여러번 시도 끝에 겨우 맞췄습니다... java 쌩 초보라 어이없는 실수를 했습니다. 아래 코드는 280ms 890B로 통과한 코드로, 파이썬으로 작성한 코드를 자바 형태로 변형했습니다. https://seolpark.tistory.com/71 [Python]BAEKJOON 1002번 터렛 https://www.acmicpc.net/problem/1002 1002번: 터렛 각 테스트 케이스마다 류재명이 있을 수 있는 위치의 수를 출력한다. 만약 류재.. 2023. 3. 2.