package kosta.mission4;
import java.util.Scanner;
public class Solution4_1 {
public int solution(String str, char c) {
int answer = 0;
str = str.toLowerCase();
c = Character.toLowerCase(c);
for(char x : str.toCharArray()) {
if(x == c) {
answer++;
}
}
return answer;
}
public static void main(String[] args) {
Solution4_1 s = new Solution4_1();
Scanner sc = new Scanner(System.in);
String str = sc.next();
char c = sc.next().charAt(0);
System.out.println(s.solution(str, c));
}
}
package kosta.mission4;
import java.util.Scanner;
public class Solution4_3 {
public String solution(String str) {
String answer = "";
int max = 0;
int pos;
while((pos=str.indexOf(' ')) != -1) {
String tmp = str.substring(0, pos);
//System.out.println(tmp);
int len = tmp.length();
if(len > max) {
max = len;
answer = tmp;
}
str = str.substring(pos+1);
}
if(str.length() > max) answer = str;
return answer;
}
public static void main(String[] args) {
Solution4_3 s = new Solution4_3();
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
System.out.println(s.solution(str));
}
}
Calender 클래스를 활용해 2022년 2월 달력 만들기
월 입력 : 2
<2022 2월>
package kosta.api;
import java.util.Calendar;
import java.util.Scanner;
public class CalenderMission {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Calendar gc = Calendar.getInstance();
int month = sc.nextInt();
gc.set(2022, month-1, 1);
int week = gc.get(Calendar.DAY_OF_WEEK); // 1~7
int day = gc.getActualMaximum(Calendar.DAY_OF_MONTH);
int count = 0;
System.out.println("<2022년 "+month+"월>");
System.out.println("일\t월\t화\t수\t목\t금\t토");
for(int i = 1; i < week; i++) {
System.out.print("\t");
}
for(int i = 1; i <= day; i++) {
System.out.print(i+"\t");
if((week + i -1)%7 == 0) {
System.out.println();
}
}
}
}