I am a beginner at Java and I am making a fun project for myself to learn more about java, I plan on randomizing videos from a preset list and displaying it to the user.
I am having trouble stopping the loop. Once you type in the kind of video you want to watch the program automatically re-loops, but i want it to ask you if you want to watch another video before relooping. Here is what I have so far:
import java.util.Scanner;
import java.util.Random;
public class YoutubeGenerator {
public static void main(String[] args) {
int randomstring = 0;
for ( ; ; ) {
System.out.println("\n ---------Youtube Video Generator 0.001 BETA------------------ \n");
System.out.println("\n ********* DISCLAIMER: WARNING - This program may direct you to violent, disturbing content, and/or vulgar language and is intended for a MATURE person only. ********* \n \n");
Scanner scan = new Scanner (System.in);
System.out.println("What kind of video from the list would you like to watch? \n");
System.out.println("Cute \n" + "Funny \n" + "WTF \n" + "Interesting \n" + "Documentary \n");
System.out.print("I want to watch: ");
String userString = scan.next();
Random rand = new Random();
if(userString.equalsIgnoreCase("cute")){
String cute1 = "https://www.youtube.com/watch?v=EdCVijVT7Wk";
String cute2 = "http://youtu.be/-XCvPptsfhI?t=7s";
String cute3 = "https://www.youtube.com/watch?v=-nkEPsSsH68";
String cute4= "https://www.youtube.com/watch?v=FZ-bJFVJ2P0";
String cute5 = "https://www.youtube.com/watch?v=argCvDpk_KQ";
System.out.println("Here's a cute video you can watch: " +cute5) ;
}
if(userString.equalsIgnoreCase("funny")){
System.out.println("Here's a funny you can watch:");
String funny1 = "https://www.youtube.com/watch?v=I59MgGlh2Mg";
String funny2 = "http://www.youtube.com/watch?v=HKMNKS-9ugY";
String funny3 = "https://www.youtube.com/watch?v=_qKmWfED8mA";
String funny4= "https://www.youtube.com/watch?v=QDFQYKPsVOQ";
String funny5 = "https://www.youtube.com/watch?v=ebv51QNm2Bk";
}
if(userString.equalsIgnoreCase("wtf")){
System.out.println("Here's a WTF video you can watch:");
String wtf1 = "https://www.youtube.com/watch?v=UfKIoSv2YEg";
String wtf2 = "https://www.youtube.com/watch?v=hcGvN0iBA5s";
String wtf3 = "http://www.youtube.com/watch?v=vxnyqvejPjI&feature=youtu.be&t=1m37s";
String wtf4= "https://www.youtube.com/watch?v=10NJnT6-sSE";
String wtf5 = "https://www.youtube.com/watch?v=DQeyjgSUlrk";
}
if(userString.equalsIgnoreCase("interesting")){
System.out.println("Here's an interesting video you can watch:");
String int1 = "https://www.youtube.com/watch?v=fYwRMEomJMM";
String int2 = "https://www.youtube.com/watch?v=1PmYItnlY5M&feature=youtu.be&t=32s";
String int3 = "https://www.youtube.com/watch?v=HgmnIJF07kg";
String int4= "https://www.youtube.com/watch?v=cUcoiJgEyag";
String int5 = "https://www.youtube.com/watch?v=BePoF4PrwHs";
}
if(userString.equalsIgnoreCase("documentary")){
System.out.println("Here's a space video you can watch: ");
String doc1 = "https://www.youtube.com/watch?v=wS_WlzdOc_A";
String doc22 = "https://www.youtube.com/watch?v=8n0SkIGARuo";
String doc33 = "https://www.youtube.com/watch?v=6LaSD8oFBZE";
String doc4= "https://www.youtube.com/watch?v=zvfLdg2DN18";
String doc5 = "https://www.youtube.com/watch?v=8af0QPhJ22s&hd=1";
}
}
}
}
Insert the following code right before the closing brace of your loop:
System.out.println("Do you want to watch another video? Enter yes or no");
String decision = scan.next();
if (decision.equalsIgnoreCase("no"))
break;
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다