백준 - 1단계 입출력과 사칙연산

이상훈·2023년 3월 3일
0

2557번

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

1000번

import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer(bf.readLine());
    int A = Integer.parseInt(st.nextToken());
    int B = Integer.parseInt(st.nextToken());
    
    int Sum = A + B;
    System.out.println(Sum);
    
    }
}

1001번

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer(bf.readLine());
    int A = Integer.parseInt(st.nextToken());
    int B = Integer.parseInt(st.nextToken());
    
    int Num = A - B;
    System.out.println(Num);
    }
}

10998번

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(bf.readLine());
        int A = Integer.parseInt(st.nextToken());
        int B = Integer.parseInt(st.nextToken());
        
        int Result = A * B;
        System.out.println(Result);
        
    }
}

1008번

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(bf.readLine());
        double A = Double.parseDouble(st.nextToken());
		double B = Double.parseDouble(st.nextToken());
		double Result = A / B;
		System.out.println(Result);
    }
} 

소수점자리가 나오게 하게 Double 사용을 하자

10869번

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(bf.readLine());
        int A = Integer.parseInt(st.nextToken());
        int B = Integer.parseInt(st.nextToken());
        System.out.println(A+B);
        System.out.println(A-B);
        System.out.println(A*B);
        System.out.println(A/B);
        System.out.println(A%B);
    }
}

10926번

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String name = sc.next();
        System.out.println(name+"??!");
        
    }
}

String을 받을때 = next();
Int를 받을때 = nextInt();

18108번

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int year = sc.nextInt();
        System.out.println(year-543);
    }
}

10430번

import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(bf.readLine());
        int A = Integer.parseInt(st.nextToken());
        int B = Integer.parseInt(st.nextToken());
        int C = Integer.parseInt(st.nextToken());
        
        System.out.println((A+B)%C);
        System.out.println(((A%C) + (B%C))%C);
        System.out.println((A*B)%C);
        System.out.println(((A%C) * (B%C))%C);
    }
}

2588번

import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        int A = Integer.parseInt(bf.readLine());
        int B = Integer.parseInt(bf.readLine());
        
        int C = B / 100;
        int D = (B % 100) / 10;
        int E = ((B % 100) % 10) / 1;
        
        System.out.println(A*E);
        System.out.println(A*D);
        System.out.println(A*C);
        System.out.println((A*E)+(A*D*10)+(A*C*100));
        
    }
}

1의 자리, 10의 자리, 100의 자리 구하기 다른방법도 생각해보기

11382번

import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(bf.readLine());
        long A = Long.parseLong(st.nextToken());
        long B = Long.parseLong(st.nextToken());
        long C = Long.parseLong(st.nextToken());
        
        System.out.println(A+B+C);
    }
}

주어진 수가 12억이 넘어가면 Long타입을 사용하자

10171번

public class Main {
    public static void main(String[] args) {
        System.out.println("\\    /\\");
        System.out.println(" )  ( ')");
        System.out.println("(  /  )");
        System.out.println(" \\(__)|");

    }
}

\ 를 사용하려면 \\

10172번

public class Main {
    public static void main(String[] args) {
        System.out.println("|\\_/|");
        System.out.println("|q p|   /}");
        System.out.println("( 0 )\"\"\"\\");
        System.out.println("|\"^\"`    |");
        System.out.println("||_/=\\\\__|");
        

    }
}

"를 사용하려면 \"

마무리

  • 컴파일에러가 너무 많았다.
  • Scanner보다 BufferedReader사용이 시간복잡도 측면에서 효율이 좋다.
  • System.out.println(); 내부는 무슨 타입으로 반환이 될까

0개의 댓글