관리 메뉴

MOMONOTE

(JAVA) 코드업 기초 100제 1038~1046 본문

알고리즘, 코딩테스트/(JAVA) 코드업 기초100제

(JAVA) 코드업 기초 100제 1038~1046

momo0503 2020. 12. 27. 18:37

1038 : [기초-산술연산] 정수 2개 입력받아 합 출력하기1

입력 : 123  -123 

출력 : 0

import java.util.Scanner;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        long input = sc.nextLong();
        long input2  = sc.nextLong();
        
        System.out.println(input+input2);
        
        sc.close();
    }
}

 

1039 : [기초-산술연산] 정수 2개 입력받아 합 출력하기2

입력 : 2147483648 2147483648

출력 : 4294967296

import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc= new Scanner(System.in);
        long input = sc.nextLong();
        long input2 = sc.nextLong();
       System.out.print(input+input2);
        
    }
}

 

 

 

1040 : [기초-산술연산] 정수 1개 입력받아 부호 바꿔 출력하기

입력 : 1

출력 : -1

import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc= new Scanner(System.in);
        long input = sc.nextLong();
       
       System.out.print(-input);
        
    }
}

 

 

1041 : [기초-산술연산] 문자 1개 입력받아 다음 문자 출력하기

입력: a

출력 : b

import java.util.*;

public class Main{
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        char word = sc.next().charAt(0);
        System.out.println((char)(word+1));
        
        
    }
}

 

 

1042 : [기초-산술연산] 정수 2개 입력받아 나눈 몫 출력하기

입력: 1 3(정수 2개(a, b)가 공백을 두고 입력된다.)

출력 : 0 (a를 b로 나눈 몫을 출력한다.)

import java.util.*;

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

 

1043 : [기초-산술연산] 정수 2개 입력받아 나눈 나머지 출력하기

입력: 10 3(정수 2개(a, b)가 공백을 두고 입력된다.)

출력 : 1 (a를 b로 나눈 나머지를 출력한다.)

import java.util.*;

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

 

 

1044 : [기초-산술연산] 정수 1개 입력받아 1 더해 출력하기

입력 : 2147483647

출력 : 2147483648

import java.util.Scanner;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        long input = sc.nextLong();
  
        System.out.println(input+1);
        
        sc.close();
    }
}

 

1045 : [기초-산술연산] 정수 2개 입력받아 자동 계산하기

입력 : 10 3 (정수 2개가 공백을 두고 입력된다.)

출력 :

첫 줄에 합
둘째 줄에 차,
셋째 줄에 곱,
넷째 줄에 몫,
다섯째 줄에 나머지,
여섯째 줄에 나눈 값을 순서대로 출력한다.
(실수, 소수점 이하 셋째 자리에서 반올림해 둘째 자리까지 출력)

13

7

30

3

1

3.33

import java.util.Scanner;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        int input = sc.nextInt();
        int input2 = sc.nextInt();
        
        System.out.println(input+input2);
        System.out.println(input-input2);
        System.out.println(input*input2);
        System.out.println(input/input2);
        System.out.println(input%input2);
        System.out.printf("%.2f",(double)input/input2);
        sc.close();
    }
}

 

 

1046 : [기초-산술연산] 정수 3개 입력받아 합과 평균 출력하기

입력 : 1 2 3 

출력 : 6 

         2.0

import java.util.Scanner;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        int input = sc.nextInt();
        int input2 = sc.nextInt();
        int input3 = sc.nextInt();
      
        System.out.println(input+input2+input3);
        System.out.printf("%.1f",(float)(input+input2+input3)/3);
        sc.close();
    }
}
Comments