백준_TEST02_사칙연산 도전하기

baekjoon_java

백준 TEST02_사칙연산 도전하기

A*B

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import java.util.*;
//1번 2번은 TEST01단계에서 해결했음. A+B , A-B
class TEST02_03{

public TEST02_03(){ // 생성자
Scanner scan = new Scanner(System.in);
int a = scan.nextInt();
int b = scan.nextInt();

if(a>0 && b<10){
System.out.println(a*b);
}
}
}
public class TEST02 {

public static void main(String[] args) {
// 생성자
TEST02_03 test02_03 = new TEST02_03();
}
}

A / B (오차범위 10-9까지)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import java.util.*;
class TEST02_04{
public TEST02_04(){
Scanner scan = new Scanner(System.in);
double a = scan.nextDouble();
double b = scan.nextDouble();

if(a>0 && b<10){
System.out.printf("%.9f",a/b);
}
}
}
public class TEST02 {

public static void main(String[] args) {
// 생성자
// TEST02_03 test02_03 = new TEST02_03();
TEST02_04 test02_04 = new TEST02_04();
}
}

사칙연산

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import java.util.*;
class TEST02_05{
public TEST02_05(){
Scanner scan = new Scanner(System.in);
double a = scan.nextDouble();
double b = scan.nextDouble();

if(a>=1 && b<=10000){
System.out.println((int)a+(int)b);
System.out.println((int)a-(int)b);
System.out.println((int)a*(int)b);
System.out.println((int)a/(int)b);
System.out.println((int)a%(int)b);
}
}
}
public class TEST02 {

public static void main(String[] args) {
// 생성자
TEST02_05 test02_05 = new TEST02_05();
}
}

나머지

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import java.util.*;
class TEST02_06{
public TEST02_06(){
Scanner scan = new Scanner(System.in);
int a = scan.nextInt();
int b = scan.nextInt();
int c = scan.nextInt();

if(a>=2 && a<=10000 && b>=2 && b<=10000 && c>=2 && c<=10000){
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);
}
}
}
public class TEST02 {

public static void main(String[] args) {
// 생성자
TEST02_06 test02_06 = new TEST02_06();
}
}

A+B-2

백준 TEST01 단계의 A+B 동일 문제. 따라서 넘어감.

설탕 배달

img

img

알고리즘

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import java.util.*;
class TEST02_08{
public TEST02_08(){
Scanner scan = new Scanner(System.in);
int box = 0 ;
int sugar_kg = scan.nextInt();
if(sugar_kg >=3 && sugar_kg <= 5000){

if(sugar_kg/5 != 0){
for(box = sugar_kg/5;box>=0;box--){
if((sugar_kg - box*5)%3==0){
box += (sugar_kg - box*5)/3;
break;
}
}
}
else if(sugar_kg == 3){
box = 1;
}
else{ box = -1; }
}
System.out.println(box);
}
}

public class TEST02 {

public static void main(String[] args) {
// 생성자
TEST02_08 test02_08 = new TEST02_08();
}
}
Share