#3 How to print int and String using Java system.out.println?

Yosuva ArulanthuJavaLeave a Comment

In this post, we are going to learn how to use print and println java statements to print Integer and String variables.

System.out.print prints the integer or string without the new line. For an example adding two print statement will display both the statement in one line.

Example:

package com.test.example;

public class Test {
        public static void main(String[] args) {
		System.out.print("Hello");
		System.out.print("World");
	}
}
Print statement output

System.out.println prints the integer or string with the new line. For an example if you add two println statement , the first line will display in first statement and second line will display second statement.

public class Test {

	public static void main(String[] args) {
		System.out.println("Hello");
		System.out.println("World");
	}

}
Println output

Other examples:

package com.test.example;

public class Test {
	public static void main(String[] args) {
		int a=3;
		int b=4;
		String s1="Hi";
		String s2="Hello";
		//print
		System.out.print(1);
		System.out.print(2);
		System.out.print(s1);
		System.out.print(s2);
		System.out.print(s1 +" "+s2);
		//println
		System.out.println(1);
		System.out.println(1 + 2);
		System.out.println("Hello" + " " +"World");
		System.out.println(a+b);
		System.out.println(s1+" "+s2);

	}
}


Output

12HiHelloHi Hello1
3
Hello World
7
Hi Hello

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.