반응형
package youn;
import java.util.Scanner;
public class Rmxakfdltrl {
public static void main(String[] args) {
System.out.println("끝말잇기 게임을 시작합니다.");
System.out.print("게임에 참가하는 인원은 몇명입니까>> ");
Scanner sc = new Scanner(System.in);
int Participant = sc.nextInt();
String arr[] = new String[Participant];
for(int i = 0 ; i < Participant ; i++){
System.out.print("이름 입력 >> ");
String name = sc.next();
arr[i] = name;
}
String word = "아버지";
System.out.println("첫 시작 단어는 " + word);
while(true) {
for(int i = 0 ; i < arr.length ; i++) {
int lastIndex = word.length()-1;
char lastChar = word.charAt(lastIndex);
System.out.print(arr[i] +">> ");
String word_1 = sc.next();
if(word_1.length()<2) {
System.out.println(arr[i]+" 틀림." + arr[i] +"허접");
System.exit(0);
}
if(word_1.charAt(0) != lastChar) {
System.out.println(arr[i]+" 틀림." + arr[i] +" 허접");
System.exit(0);
}
word = word_1;
}
}
}
}
반응형
'프로그래밍 공부 > java' 카테고리의 다른 글
[JAVA] 이것이 자바다 6장 확인 문제 : 싱글톤 패턴을 사용해서 ShopService 클래스 작성하기 (0) | 2023.01.14 |
---|---|
[JAVA] 이것이 자바다 6장 확인 문제 :MemberService 클래스에서 login(), logout() 메소드 선언, 출력하기 (0) | 2023.01.14 |
[JAVA] 피보나치 수열에서 4백만 이하이면서 짝수인 항의 합 (0) | 2023.01.12 |
[JAVA] 1000보다 작은 자연수 중에서 3 또는 5의 배수를 모두 더하면? (0) | 2023.01.10 |
[JAVA] 상속 (0) | 2023.01.06 |