자바

[JAVA] 백준 기초공부 4

코딩하는둥이 2022. 12. 3. 22:34

1. 1157번  단어공부

https://www.acmicpc.net/problem/1157

 

1157번: 단어 공부

알파벳 대소문자로 된 단어가 주어지면, 이 단어에서 가장 많이 사용된 알파벳이 무엇인지 알아내는 프로그램을 작성하시오. 단, 대문자와 소문자를 구분하지 않는다.

www.acmicpc.net

 

 

2. 코딩 

import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner input = new Scanner(System.in);
        int apb[] = new int[26]; 
        String str = input.next(); 
        str = str.toUpperCase();
        for(int i=0; i<str.length(); i++){
            apb[str.charAt(i)-'A']++;
        }
        int max = 0, ans=0;
        for(int i=0; i<apb.length; i++){
            if(max < apb[i]){
                max = apb[i];
                ans = i;
            }
            else if(max == apb[i]){
                ans = -2; 
            }
        }
        System.out.printf("%s", Character.toString(ans+'A')); 
    }
}

1. 11654번 아스키코드

https://www.acmicpc.net/problem/11654

 

11654번: 아스키 코드

알파벳 소문자, 대문자, 숫자 0-9중 하나가 주어졌을 때, 주어진 글자의 아스키 코드값을 출력하는 프로그램을 작성하시오.

www.acmicpc.net

2.

import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
 
		Scanner in = new Scanner(System.in);
 
		int ch = in.next().charAt(0);
        
		System.out.print(ch);
	}
}

'자바' 카테고리의 다른 글

[JAVA] 인터페이스  (3) 2022.12.11
[JAVA] 소수점 맞춰 출력  (0) 2022.12.03
[JAVA] 추상클래스  (0) 2022.12.03
[JAVA] 출력 형식  (0) 2022.11.26
[JAVA] 백준 기초공부 3  (0) 2022.11.26