공부기록/백준
[백준] 10807번 개수세기, 10871번 X보다 작은 수, 10818번 최소, 최대, 10699번 오늘 날짜
메델
2023. 2. 12. 12:51
10699번 오늘 날짜
import java.text.SimpleDateFormat;
import java.util.Date;
public class Main {
public static void main(String[] args) {
Date now = new Date();
String s = now.toString();
SimpleDateFormat formatType= new SimpleDateFormat("yyyy-MM-dd");
System.out.println(formatType.format(now));
}
}
10818번 최소, 최대
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int[] array = new int[n];
for(int i=0; i<n; i++) {
array[i] = scanner.nextInt();
}
int min = array[0];
int max = array[0];
for(int i=1; i<array.length; i++) {
if(min> array[i]) {
min = array[i];
}
if(max < array[i]) {
max = array[i];
}
}
System.out.print(min +" "+ max);
}
}
10871번 X보다 작은 수
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int[] array = new int[n];
int x = scanner.nextInt();
for(int i=0; i<n; i++) {
array[i] = scanner.nextInt();
}
for(int i=0; i<array.length; i++) {
if( x > array[i]) {
System.out.print(array[i]+ " ");
}
}
scanner.close();
}
}
10807번 개수세기
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int number = 0;
int[] numbers = new int[n];
for(int i=0; i<n; i++) {
numbers[i] = scanner.nextInt();
}
int v = scanner.nextInt();
scanner.close();
for(int i=0; i<numbers.length; i++) {
if(v == numbers[i]) {
number++;
}
}
System.out.println(number);
}
}