[μ½λνΈλ¦¬/JAVA] μ’ λ μ΄λ €μ΄ μν μ μ
λ΄ μ½λ
μ°μ νμ Aμ Bκ° μλ€.
Aμ Bμ μμ΄,μνμ μλ₯Ό κ°κ° μ λ ₯λ°μμΌνλ€ ( = Scanner)
쑰건 1. μμ΄ μ μμ μκ΄x μν μ μκ° λμΌλ©΄, λμ νμ μ΄λ¦ μΆλ ₯
쑰건 2. μν μ μκ° κ°μΌλ©΄ μμ΄ μ μκ° λμ νμμ μ΄λ¦ μΆλ ₯
λ¨, μν μ μμ μμ΄ μ μκ° λ λ€ λμΌνκ² μ£Όμ΄μ§λ κ²½μ°λ μμ.
κ·ΈλΌ μ λ ₯ λ°μμΌν μ μκ° aμ μμ΄,μν / bμ μμ΄, μν 4κ°λ€.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int aEng = sc.nextInt();
int aMath = sc.nextInt();
int bEng = sc.nextInt();
int bMath = sc.nextInt();
}
}
κ·Έλ¦¬κ³ μ‘°κ±΄ 1. μμ΄ μ μμ μκ΄x μν μ μκ° λμΌλ©΄, λμ νμ μ΄λ¦ μΆλ ₯
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int aEng = sc.nextInt();
int aMath = sc.nextInt();
int bEng = sc.nextInt();
int bMath = sc.nextInt();
if ( aMath > bMath ){
System.out.print("A");
} else {
System.out.print("B")
}
}
}
쑰건 2. μν μ μκ° κ°μΌλ©΄ μμ΄ μ μκ° λμ νμμ μ΄λ¦ μΆλ ₯
if ( aMath > bMath || (aMath == bMath) && (aEng > bEng)){
aκ° μ‘°κ±΄1κ³Ό 쑰건2μ€μμ νλλΌλ λ§μ‘±νλ€λ©΄ Aλ₯Ό μΆλ ₯
μλλ©΄ Bλ₯Ό μΆλ ₯νλ κ±Έλ‘ νλ€.
κ·Έ κ³Όμ μμ if else ifκΉμ§λ λ무 μ½λκ° κΈΈμ΄μ Έμ, μ§§κ² λ€μ μ€μ¬λ³΄μλ€.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int aMath = sc.nextInt();
int aEng = sc.nextInt();
int bMath = sc.nextInt();
int bEng = sc.nextInt();
if ( aMath > bMath || (aMath == bMath) && (aEng > bEng)){
System.out.print("A");
} else {
System.out.print("B");
}
}
}
κ·Έλ¦¬κ³ λ¬Έμ μμ
첫 λ²μ§Έ μ€μ A νμμ μν μ μμ μμ΄ μ μκ° κ³΅λ°±μ μ¬μ΄μ λκ³ μ£Όμ΄μ§λλ€.
λ λ²μ§Έ μ€μ B νμμ μν μ μμ μμ΄ μ μκ° κ³΅λ°±μ μ¬μ΄μ λκ³ μ£Όμ΄μ§λλ€.
μν μ μκ° λ¨Όμ μ λ ₯λ°λλ€κ³ νλλ°, λλ μ§κΈ μ΄ μ½λλ§κ³ κ·Έ μμ μ½λλ₯Ό 보면 Engλ¨Όμ μ λ ₯ λ°λλ‘ ν΄λ¨λ€.
κ·Έλμ μ€λ₯κ° λ΄λ€ ;-; μ λ ₯ κ° μμλ νμ νμΈνκΈ°.
ν μ€νΈ μ¬λ¬λ² λλ Έμ λ μ€νμ λ¬Έμ κ° μμ΄μ μ μΆ
νκ³
μ²μ νλ¦°κ±°λ μμ λ§νλ―μ΄, μ λ ₯κ° μμλ₯Ό νμΈνμ§ λͺ»ν΄μ μΌμ΄λ μΌ!
νμ ν μ€νΈμ½λ μ λ ₯ λ§μ΄ν΄λ³΄κΈ°.
λ¬Έμ λ λλ² μΈλ² μ½μ΄λ³΄κ³ λΆμνκ³ μ°¨κ·Όμ°¨κ·Ό μ μ΄μ νκΈ°
μ λ΅
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// λ³μ μ μΈ
int a_math, a_eng;
int b_math, b_eng;
// μ
λ ₯
a_math = sc.nextInt();
a_eng = sc.nextInt();
b_math = sc.nextInt();
b_eng = sc.nextInt();
// μΆλ ₯
if(a_math > b_math || (a_math == b_math && a_eng > b_eng))
System.out.println("A");
else
System.out.println("B");
}
}