과제가 있습니다 ... 코드가 아래에 있습니다. 몇 가지 질문이 있습니다 ... 미리 감사드립니다. 이 cludgey을 보이는 경우 초급 자바 학생은 ...> 웃지 마십시오.> 아래 코드 ...Java ... While 루프 프로그램
/*
* Getting to know you...
* @author Elle dela Victoria
* @version 092812
*/
import java.util.*;
public class A15_1
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.print(
"Mind answering some questions for me?\n" +
"Type quit when you're ready to leave.\n");
while(true)
{
System.out.print("Does your name start with the letter H? ");
input.nextLine();
int ans = (int)(Math.random() * 5);
if (ans == 0)
System.out.println("That's awesome!");
if (ans == 1)
System.out.println("Awww, how unfortunate!");
if (ans == 2)
System.out.println("You're amazing at this!");
if (ans == 3)
System.out.println("LOL!");
if (ans == 4)
System.out.println("WTF!! That's horrible!");
System.out.print("Are you male? ");
input.nextLine();
int ans1 = (int)(Math.random() * 5);
if (ans1 == 0)
System.out.println("That's awesome!");
if (ans1 == 1)
System.out.println("Awww, how unfortunate!");
if (ans1 == 2)
System.out.println("You're amazing at this!");
if (ans1 == 3)
System.out.println("LOL!");
if (ans1 == 4)
System.out.println("WTF!! That's horrible!");
System.out.print("Are you female?");
input.nextLine();
int ans2 = (int)(Math.random() * 5);
if (ans2 == 0)
System.out.println("That's awesome!");
if (ans2 == 1)
System.out.println("Awww, how unfortunate!");
if (ans2 == 2)
System.out.println("You're amazing at this!");
if (ans2 == 3)
System.out.println("LOL!");
if (ans2 == 4)
System.out.println("WTF!! That's horrible!");
System.out.print("Are you in school right now?");
input.nextLine();
int ans3 = (int)(Math.random() * 5);
if (ans3 == 0)
System.out.println("So angry when you're sober!");
if (ans3 == 1)
System.out.println("Awww, how unfortunate!");
if (ans3 == 2)
System.out.println("You're amazing at this!");
if (ans3 == 3)
System.out.println("LOL!");
if (ans3 == 4)
System.out.println("WTF!! That's horrible!");
String userinput = input.nextLine();
if (userinput.equalsIgnoreCase("quit"))
break;
}
}
}
- 사용할 수있는 방법이 내 내가 필요없이 물어 모든 질문에 대한 문 IF 각 질문의 문자열 이름을 변경 하시겠습니까?
- 이러한 if 문에 대해 메서드 (?)를 만들 수있는 방법이 있습니까? 그래서 질문하는 모든 질문에 대해 작성할 필요가 없습니다.
- 사용자가 10 초 내에 답변을 입력하지 않으면 답변을 요청하는 타이머를 갖고 싶습니다. 어떻게해야합니까?
@ 루이지 멘도자 - 좋은 일을 계속하십시오! ;) –
@RichardJPLeGuen 할 수있을 때마다 나는 그것을하는 경향이 있습니다. –
짧은 답변 : 1) 아니요, 2) 네,하지만 메서드는 모든'if' 문과'String' 문을 포함합니다. 3) 가능한 일이지만 초보자라고 말하는 것이므로 콘솔 응용 프로그램에서이 기능을 찾지 않는 것이 좋습니다. –