How to print output in quotes in Java?

By | September 18, 2017

To print constants in quotes:

To print constants in quotes, write them inside “\”constant\””.

To print variables in quotes:

To print variables in quotes, write them inside “\””+variable+”\””.

Example:

package mypack;
import java.util.Scanner;
   public class HelloUser { 
      public static void main(String []args){ 
         Scanner sc=new Scanner(System.in); 
         System.out.println("Enter user name..."); 
         String userName; 
         userName=sc.nextLine(); 
         System.out.println("\"Welcome to this site\""); 
         System.out.println( "\""+userName+"\""); 
         sc.close(); 
      }
   }

Result:

 

Leave a Reply