[Solved] Accept arbitrary multi-line input of String type and store it in a variable


From what I gather, you’re trying to get input from a user until that user types -1. If thats the case, please see my function below.

public static void main (String[] args)
{
    // Scanner is used for I/O
    Scanner input = new Scanner(System.in);

    // Prompt user to enter text
    System.out.println("Enter something ");

    // Get input from scanner by using next()
    String text = input.next();

    // this variable is used to store all previous entries
    String storage = "";

        // While the user does not enter -1, keep receiving input
        // Store user text into a running total variable (storage)
        while (!text.equals("-1")) {
            System.out.println("You entered: " + text);
            text = input.next();
            storage = storage + "\n" + text
    }
}

I’ve left comments in that code block but I’ll reiterate it here. First we declare our I/O object so that we can get input from the keyboard. We then ask the user to "Enter something" and wait for the user to enter something. This process is repeated in the while loop until the user specifically types -1.

solved Accept arbitrary multi-line input of String type and store it in a variable