(아래의 키워드를 사용해주세요!)
- 기철초풍, 멋있는, 재미있는
- 도전적인, 노란색의, 바보같은
- 돌고래, 개발자, 오랑우탄
- 실행 화면
import java.util.Random;
public class RandomNicknameCreator {
public static void main(String[] args) {
String[] firstList = {"기철초풍", "멋있는", "재미있는"};
String[] secondList = {"도전적인", "노란색의", "바보같은"};
String[] thirdList = {"돌고래", "개발자", "오랑우탄"};
Random random = new Random();
int first_randomIndex = random.nextInt(firstList.length);
int second_randomIndex = random.nextInt(secondList.length);
int third_randomIndex = random.nextInt(thirdList.length);
System.out.println("랜덤 닉네임 : " + firstList[first_randomIndex]+secondList[second_randomIndex] + thirdList[third_randomIndex]);
}
}
import java.util.Random;
public class RandomNicknameCreator {
private String[] firstList = {"기철초풍", "멋있는", "재미있는"};
private String[] secondList = {"도전적인", "노란색의", "바보같은"};
private String[] thirdList = {"돌고래", "개발자", "오랑우탄"};
private String createRandomNickname() {
Random random = new Random();
int first_randomIndex = random.nextInt(firstList.length);
int second_randomIndex = random.nextInt(secondList.length);
int third_randomIndex = random.nextInt(thirdList.length);
String name = firstList[first_randomIndex]+secondList[second_randomIndex] + thirdList[third_randomIndex];
return name;
}
public static void main(String[] args) {
RandomNicknameCreator randomNicknameCreator = new RandomNicknameCreator();
String myNickname = randomNicknameCreator.createRandomNickname();
System.out.println("랜덤 닉네임 : " + myNickname);
}
}
- 함수 사용 전
- 함수 사용 후
- 둘 다 시간이 11~16초 사이의 시간이 걸렸다.
- System.currentTimeMillis()를 사용