소수 판별
public class PrimeNumber {
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int input = Integer.parseInt(br.readLine());
boolean isPrime = true;
int sqrt = (int) Math.ceil(Math.sqrt(input));
for (int i = 2; i <= sqrt; i++) {
if (input % i == 0) {
isPrime = false;
break;
}
}
if (isPrime) {
bw.write("true\\n");
} else {
bw.write("false\\n");
}
bw.flush();
br.close();
bw.close();
}
}
두 수 비교하기
public class ConditionOperator {
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
String s = br.readLine();
String[] strArr = s.split(" ");
if (strArr.length != 2) {
return;
}
int a = Integer.parseInt(strArr[0]);
int b = Integer.parseInt(strArr[1]);
bw.write((a > b ? ">" : (a < b ? "<" : "=")));
bw.flush();
br.close();
bw.close();
}
}
구구단
public class ex4_12 {
public static void main(String[] args) {
for (int i = 2; i <= 9; i+=3) {
for (int j = 1; j <= 3; j++) {
for (int k = 0; k < 3; k++) {
if (i + k < 10) {
System.out.printf("%d*%d=%d\\t", i + k, j, (i + k) * j);
}
}
System.out.println();
}
System.out.println();
}
}
}
7의 배수
public class Seven {
public static void main(String[] args) {
int sum = 0;
for (int i = 0; i <= 100; i++) {
if (i % 7 == 0) {
sum += i;
}
}
System.out.println("sum = " + sum);
// 0 + 7 + 14 + 21 + 28 + 35 + 49 + 56 + 63 + 70 + 77 + 84 + 91 + 98
}
}