Java Program to Print String

« Previous Program Next Program »

Print String

To print a string in Java Programming, first you have to ask to the user to enter the string and place that string in any variable say str, and now place this variable str in the bracket of System.out.print().

Java Programming Code to Print String

Following Java Program ask to the user to enter a string like your first name, then it will display your first name after Hello,:

/* Java Program Example - Print String */
import java.util.Scanner;

public class JavaProgram
   public static void main(String args[])
      String str;
      Scanner scan = new Scanner(;
      System.out.print("Enter Your First Name : ");
      str = scan.nextLine();
      System.out.print("Hello, " + str);

When the above Java Program is compile and executed, it will produce the following output:

Java Program print string

Same Program in Other Languages

You may also like to learn and practice the same program in other popular programming languages:

Java Online Test

« Previous Program Next Program »

© Copyright 2021. All Rights Reserved.