#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    1
    Rep Power
    0

    Help with WHILE and IF


    So I have to write a program using the while statement that works is a loop with numbers 1-5 and quits when pressing 0. This is what I have so far; the program works if I press the numbers in order, however if I want to just around ( press 3 first instead of 1) nothing gets displayed. Thanks guys!

    import java.util.Scanner;
    public class loop {
    public static void main (String[] args){
    Scanner input = new Scanner(System.in);
    System.out.print("Enter a number 1-5, 0 to quit ");
    int Likes = input.nextInt();

    do{
    if (Likes ==1)
    System.out.println("Inglorius Bastards");
    Likes=input.nextInt();
    if (Likes ==2)
    System.out.println("Skyrim");
    Likes=input.nextInt();
    if (Likes ==3)
    System.out.println("Android");
    Likes=input.nextInt();
    if (Likes ==4)
    System.out.println("Next Gen Xbox");
    Likes=input.nextInt();
    if (Likes ==5)
    System.out.println("Dark Fantasy");
    Likes=input.nextInt();}
    while (Likes!=0);
    if (Likes ==0)
    System.out.println("Goodbye!");

    }

    }
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    194
    Rep Power
    76
    use if else's for this
    Code:
    if (Likes==1){
      System.out.println("Inglorius Bastards");
      Likes=input.nextInt();
    }else if (Likes ==2)

IMN logo majestic logo threadwatch logo seochat tools logo