본문 바로가기
JAVA

벼락치기 day1

by 801lhy 2020. 4. 8.

if else 문

import java.util.*;

public class Solution {

    private static final Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {
        int N = scanner.nextInt();
        if(N%2!=0)System.out.println("Weird"); // 홀수인경우 
        else if(N>=2 && N<=5) System.out.println("Not Weird"); // 2 이상 5이하
        else if(N>=6 && N<=20) System.out.println("Weird"); // 6이상 20 이하
        else System.out.println("Not Weird"); // 그 외
    }
}

입-출력

import java.util.Scanner;

public class Solution {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int i = scan.nextInt();
        double d = scan.nextDouble(); // 여기서 enter 치고
        scan.nextLine();// 이걸 해줘야
        String s = scan.nextLine(); // 정상출력, next() 는 공백전까지 입력 nextLine() 은 엔터전까지 입력
               
        System.out.println("String: " + s);
        System.out.println("Double: " + d);
        System.out.println("Int: " + i);
    }
}

format 입출력

import java.util.Scanner;

public class Solution {

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        System.out.println("================================");
        for(int i=0;i<3;i++)
        {
            String s1=sc.next();
            int x=sc.nextInt();

            System.out.print(String.format("%-15s",s1));
            System.out.println(String.format("%03d",x));
        }
        System.out.println("================================");

    }
}

'JAVA' 카테고리의 다른 글

벼락치기 day4 - Stack  (0) 2020.04.12
벼락치기 day3 - HashMap 개념, 알고리즘 문제 풀이  (0) 2020.04.11
벼락치기 day2 -Hash  (0) 2020.04.09
JAVA 설치, 환경변수 설정, Eclipse 설ㅊ  (0) 2020.04.04
01. java, 연산자, 변수  (1) 2019.06.06