How can I pause a loop until I get a users input?

codeacode

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";
    }  
    }
}
}
Hans Brende

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] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

How can I get javascript to write dates in my input boxes?

분류에서Dev

How can I get time efficent by creating an array with for loop?

분류에서Dev

How can I get the tkinter entry from a loop

분류에서Dev

How can I preset aliases for all users?

분류에서Dev

In Python, how to write strings in a file in a loop and before the loop stops, I can get the results runtimely?

분류에서Dev

How can I get a RejectedExecutionException

분류에서Dev

How can I get a solution for this?

분류에서Dev

Can I customize users privilege?

분류에서Dev

How can I break a symbolic link loop?

분류에서Dev

How can I iterate through a function with for loop?

분류에서Dev

How can I resolve this loop in c#?

분류에서Dev

How can I create additional users in Ubuntu OpenStack?

분류에서Dev

How can I audit users and access attempts to SSH on my server?

분류에서Dev

How can I get $_GET values to a variable

분류에서Dev

how to get a list of users I have interacted with in a messaging system

분류에서Dev

How can I preform a GET request when user input equals current time?

분류에서Dev

how can i modify main method to get input and output from the comandline?

분류에서Dev

how can i loop for store items i want in ExtJS XTemplate?

분류에서Dev

Javascript Pause Loop until function is finished

분류에서Dev

How do I manually pause an activity in Android?

분류에서Dev

How do I toggle play/pause with SoundJS?

분류에서Dev

Using pdb, how can I run a program and pause where reaching an error?

분류에서Dev

How can I get an array from an If statement?

분류에서Dev

How can i get the hasClass of click target?

분류에서Dev

How can i get request in Filter

분류에서Dev

How can I get SSRS to create subheadings?

분류에서Dev

How can I get the CurrentSite object in Orchard?

분류에서Dev

How can I get FacetFilter work properly?

분류에서Dev

How can I get the type of a Type?

Related 관련 기사

  1. 1

    How can I get javascript to write dates in my input boxes?

  2. 2

    How can I get time efficent by creating an array with for loop?

  3. 3

    How can I get the tkinter entry from a loop

  4. 4

    How can I preset aliases for all users?

  5. 5

    In Python, how to write strings in a file in a loop and before the loop stops, I can get the results runtimely?

  6. 6

    How can I get a RejectedExecutionException

  7. 7

    How can I get a solution for this?

  8. 8

    Can I customize users privilege?

  9. 9

    How can I break a symbolic link loop?

  10. 10

    How can I iterate through a function with for loop?

  11. 11

    How can I resolve this loop in c#?

  12. 12

    How can I create additional users in Ubuntu OpenStack?

  13. 13

    How can I audit users and access attempts to SSH on my server?

  14. 14

    How can I get $_GET values to a variable

  15. 15

    how to get a list of users I have interacted with in a messaging system

  16. 16

    How can I preform a GET request when user input equals current time?

  17. 17

    how can i modify main method to get input and output from the comandline?

  18. 18

    how can i loop for store items i want in ExtJS XTemplate?

  19. 19

    Javascript Pause Loop until function is finished

  20. 20

    How do I manually pause an activity in Android?

  21. 21

    How do I toggle play/pause with SoundJS?

  22. 22

    Using pdb, how can I run a program and pause where reaching an error?

  23. 23

    How can I get an array from an If statement?

  24. 24

    How can i get the hasClass of click target?

  25. 25

    How can i get request in Filter

  26. 26

    How can I get SSRS to create subheadings?

  27. 27

    How can I get the CurrentSite object in Orchard?

  28. 28

    How can I get FacetFilter work properly?

  29. 29

    How can I get the type of a Type?

뜨겁다태그

보관