본문 바로가기

프로그래밍/자바

[자바] 정올 593 ~ 601 : 문자열1 - 자가진단1~9

728x90
반응형
SMALL

자가진단1 : 593

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int a = 33;
        while(true){
            System.out.print("ASCII code =? ");
            a = sc.nextInt();
            if(a >=33 && a <= 127) System.out.println((char)a);
            else break;
        }
    }
}

자가진단2 : 594

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc =  new Scanner(System.in);
        String my = sc.nextLine();
        System.out.println(my.repeat(2));
    }
}

자가진단3 : 595

public class Main {
    public static void main(String[] args) {
        String str  =  "Hong Gil Dong";
        System.out.println(str.substring(3,7));
    }
}

자가진단4

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        int i = sc.nextInt();
        if( i >= str.length()){
            for(int j = str.length() -1; j >= 0; j--) System.out.print(str.charAt(j));
        }else{
            for(int j = str.length() -1; j > str.length() -1 - i; j--) System.out.print(str.charAt(j));
        }

    }
}

자가진단5

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int sum = 0;
        String str;
        for(int i = 0; i < 2; i++){
            str = sc.nextLine();
            sum += str.length();
        }
        System.out.println(sum);
    }
}

자가진단6

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char a;
        while (true) {
            a = sc.next().charAt(0);
            if ( ((int)a >= 65 && (int)a <= 90) || ((int)a >= 97 && (int)a <= 122)) System.out.println(a);
            else if (Character.isDigit(a)) System.out.println((int)a);
            else break;
        }
    }//end main()
}

자가진단7

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 = "";
       for(int i = 0;i<str.length();i++){
           if(((int)str.charAt(i) >= 65 && (int)str.charAt(i) <= 90) || ((int)str.charAt(i) >= 97 && (int)str.charAt(i) <= 122)) answer += str.charAt(i);
       }//end for
        System.out.println(answer.toUpperCase());
    }
}

자가진단8

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        String[] arr = str.split( " ");
        System.out.println(arr.length);
    }
}

자가진단9

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
            for(int i = 1; i < str.length(); i++){
                System.out.print(str.substring(str.length()-i));
                System.out.println(str.substring(0, str.length()-i));
            }
        System.out.println(str);
        }
    }
728x90
반응형
LIST