0

I have been trying to put a reset to this. So that you can continue forever until you hit enter (blank space) at the movie title selection.

It runs once and not more, can someone help me?

package stack;

import java.util.Scanner;

public class Stack {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);

        while (true) {

            String temp = input.nextLine();

            if (temp.length() > 0) {
                info in = new info();
                in.setTitel(temp);
                in.filmnamn();

                int nr[] = new int[3];
                int sum = 0;
                System.out.println();

                for (int i = 0; i < nr.length; i++) {
                    System.out.print("Judge " + (i + 1) + " gives the movie: ");
                    nr[i] = input.nextInt();
                    sum += nr[i];
                }
            }
            if (temp.isEmpty())
                break;
        }
    }
}

This is the second class:

package stack;

public class info {

     private String namn;

     public void setTitel(String film) {

         namn=film;      

     }

     public String getTitel() {

         return namn;
     } 

     public void filmnamn() {
         System.out.printf("Movie title: %s", getTitel());
     }

}
Loris Securo
  • 7,178
  • 2
  • 15
  • 25
oneoe
  • 43
  • 1
  • 2
  • 7
  • Have you tried using the debugger? How is the code getting to the break statement? Is temp empty at that point? – Flaom May 27 '17 at 22:17
  • 1
    input.nextLine(); // Consume newline left-over. So added this code in the last line of my program and it worked. I do not completly understand the other thread but will read more tomorow. Thank you all for the help <3 – oneoe May 27 '17 at 22:31

0 Answers0