[JAVA] ์ฝ”๋“œ์—… 1021 ~1030 ๐Ÿ”ฅ

1021

๋‹จ์–ด 1๊ฐœ ์ž…๋ ฅ๋ฐ›์•„ ๊ทธ๋Œ€๋กœ ์ถœ๋ ฅํ•˜๊ธฐ

import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		String value = scan.next();
		System.out.println(value);
	}
}

1022

๋ฌธ์žฅ 1๊ฐœ ์ž…๋ ฅ๋ฐ›์•„ ๊ทธ๋Œ€๋กœ ์ถœ๋ ฅํ•˜๊ธฐ

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String value = scan.nextLine();
        System.out.printf(value);
    }
}

next()์™€ nextLine()์˜ ์ฐจ์ด

  • next() ๋ฌธ์ž ๋˜๋Š” ๋ฌธ์ž์—ด์„ ๊ณต๋ฐฑ์„ ๊ธฐ์ค€์œผ๋กœ ํ•œ๋‹จ์–ด๋˜๋Š” ํ•œ๋ฌธ์ž ์”ฉ ์ž…๋ ฅ ๋ฐ›๋Š”๋‹ค.
  • nextLine() ๋ฌธ์ž ๋˜๋Š” ๋ฌธ์žฅ ํ•œ๋ผ์ธ ์ „์ฒด๋ฅผ ์ž…๋ ฅ ๋ฐ›๋Š”๋‹ค.

ex) Hello world ์ž…๋ ฅ

next()

nextLine()

1023

์‹ค์ˆ˜ 1๊ฐœ ์ž…๋ ฅ๋ฐ›์•„ ๋ถ€๋ถ„๋ณ„๋กœ ์ถœ๋ ฅํ•˜๊ธฐ

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String value = scan.next();
        String valueList[] = value.split("[.]");
        System.out.println(valueList[0]);
        System.out.println(valueList[1]);
    }
}

1024

๋‹จ์–ด 1๊ฐœ ์ž…๋ ฅ๋ฐ›์•„ ๋‚˜๋ˆ„์–ด ์ถœ๋ ฅํ•˜๊ธฐ

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String value = scan.next();
        char valueList[] = new char[value.length()];
        for(int i=0; i < valueList.length; i++){
            valueList[i] = value.charAt(i);
        }
       
        for(int i=0; i < valueList.length; i++){
           System.out.println("'"+valueList[i]+"'");
        }
       
    }
}

1025

์ •์ˆ˜ 1๊ฐœ ์ž…๋ ฅ๋ฐ›์•„ ๋‚˜๋ˆ„์–ด ์ถœ๋ ฅํ•˜๊ธฐ

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        char charArr[] = scan.next().toCharArray();

        for(int i=0; i < charArr.length; i++){
            System.out.print("["+charArr[i]);
            for(int j=0; j< 4-i; j++){
                System.out.print("0");
            }
            System.out.println("]");
        }

    }
}

1026

์‹œ๋ถ„์ดˆ ์ž…๋ ฅ๋ฐ›์•„ ๋ถ„๋งŒ ์ถœ๋ ฅํ•˜๊ธฐ

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String value = scan.next();
		String valueArr[] = value.split(":");
		System.out.printf("%d",Integer.parseInt(valueArr[1]));
	}
}

1027

๋…„์›”์ผ ์ž…๋ ฅ ๋ฐ›์•„ ํ˜•์‹ ๋ฐ”๊ฟ” ์ถœ๋ ฅํ•˜๊ธฐ

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String value = scan.next();
		String[] valueArr = value.split("[.]");
		System.out.printf("%02d-%02d-%04d", Integer.parseInt(valueArr[2]),Integer.parseInt(valueArr[1]),Integer.parseInt(valueArr[0]));
	}
}

1028

์ •์ˆ˜ 1๊ฐœ ์ž…๋ ฅ๋ฐ›์•„ ๊ทธ๋Œ€๋กœ ์ถœ๋ ฅํ•˜๊ธฐ2

import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		long value = scan.nextLong();
		System.out.println(value);
	}
}

1029

์‹ค์ˆ˜ 1๊ฐœ ์ž…๋ ฅ๋ฐ›์•„ ๊ทธ๋Œ€๋กœ ์ถœ๋ ฅํ•˜๊ธฐ2

import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		double value = scan.nextDouble();
		System.out.printf("%.11f",value);
	}
}

1030

์ •์ˆ˜ 1๊ฐœ ์ž…๋ ฅ๋ฐ›์•„ ๊ทธ๋Œ€๋กœ ์ถœ๋ ฅํ•˜๊ธฐ3

import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		long value = scan.nextLong();
		System.out.println(value);
	}
}

์ข‹์€ ์›นํŽ˜์ด์ง€ ์ฆ๊ฒจ์ฐพ๊ธฐ