Skip to content
Advertisement

Putting a user’s input in between double quotes

import java.util.Scanner;
public class InputTest {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);

        System.out.print("Enter your first name : ")
        String Answer = input.next();
        System.out.println(Answer + " is your first name.");
    }

}

if the user inputs John,

the output will say : John is your first name.

My question : How can I change the output to "John" instead of John.

Advertisement

Answer

Try this

System.out.print(""" + scanner + """ + "is not a valid command. Please try again : ");

This escapes the " by using .

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement