본문 바로가기

프로그래밍/자바

[자바] 정올 182 ~ 188 : 문자열1 - 형성평가1 ~ 7

728x90
반응형
SMALL

형성평가1 : 182

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char a = sc.next().charAt(0), b = sc.next().charAt(0);
        System.out.print(((int)a + (int)b) + " " + (Math.abs((int)a - (int)b)) );
    }
}

형성평가2 : 183

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        System.out.println(str.substring(0,5));
    }
}

형성평가3 : 184

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        String answer = "";
        char[] arr = str.toCharArray();
        for(char i : arr){
            if(Character.isDigit(i)) answer += i;
            else if(((int)i >= 65 && (int) i <=90) || ((int)i >= 97 && (int)i <=122)) answer += Character.toLowerCase(i);
        }
        System.out.println(answer);
    }
}

형성평가4 : 185

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        char s = sc.next().charAt(0);
        char[] arr = str.toCharArray();
        boolean a = true;
        for(int i = 0; i < arr.length; i++){
            if(arr[i] == s){
                a = false;
                System.out.println(i);
                break;
            }
        }
        if(a) System.out.println("No");
    }
}

형성평가5 : 186

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] arr = sc.nextLine().split("\\s+");
        int max = 0;
        for(String i : arr){

            max = max > i.length() ? max : i.length();
        }
        System.out.println(max);
    }
}

형성평가6 : 187

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        int a;
        while(str.length() > 1){
            a = sc.nextInt();
            if(a >= str.length()) str = str.substring(0, str.length() -1);
            else str = str.substring(0,a-1)+str.substring(a);
            System.out.println(str);
        }
    }
}

형성평가7 : 188

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String li = sc.nextLine().trim();
        String[] arr = li.split("\\s+");
        int i = 1;
        for(String a : arr){
            System.out.println(i+". " + a);
            i++;
        }
    }
}
728x90
반응형
LIST