import java.util.Scanner;
public class Quiz_02 {
public static int bigger(int a,int b) {
int result;
if(a>b) {
result=a;
}else if(a<b) {
result=b;
}else {
result=0;
}
return result;
}
public static String translate(String a) {
String result;
if(a.contentEquals("apple")) {
result="사과";
}else if(a.contentEquals("airplane")) {
result="비행기";
}else {
result="이 사전에 없는 단어입니다.";
}
return result;
}
public static int myRand(int a, int b) {
int result;
int max;
int min;
if(a>b) {
max=a;
min=b;
}else {
max=b;
min=a;
}
result=(int)((Math.random()*(max-min+1)+min));
return result;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("첫번째 수를 입력하세요 >");
int x=Integer.parseInt(sc.nextLine());
System.out.print("두번째 수를 입력하세요 >");
int y=Integer.parseInt(sc.nextLine());
System.out.print("단어를 입력하세요 >");
String text=sc.nextLine();
System.out.println(x+" 과(와) "+y+" 중 에서 더 큰 수는 " + bigger(x,y));
System.out.println(text+" 를(을) 한국어로 번역하면 " +translate(text));
System.out.println(x+" 과(와) "+y+" 사이의 난수는 " +myRand(x,y));
/*
System.out.println(bigger(10,9));
//더 큰 수를 반환해야함 10-만약 두수가 같다면 0을 반환
System.out.println(translate("apple")); //사과
System.out.println(translate("airplane")); //비행기
System.out.println(myRand(5,15)); //5~15사이의 난수 반환
*/
}
}
Comment