← Back to Core Java Course | Chapter 2: Input & Output | Lesson 1 of 6

Java का System.out.println()

System.out.println वह है जैसे एक Java program आपकी screen पर messages दिखाता है, कुछ announce करता एक loudspeaker जैसा। println भी बाद में एक नई line पर move होता है।
Syntax
java
System.out.println(value);
System.out.print(value);

Basic Printing

println() आप जो भी पास करें (numbers, strings, objects) उसे इसके text form में convert करता है और इसे console में लिखता है, फिर अपने आप output cursor को अगली line की शुरुआत में move करता है।

उदाहरण: Basic Printing

java
// Define the class Main
public class Main {
	// Program entry point: the JVM starts running here
	public static void main(String[] args) {
		// Print a line to the console
		System.out.println(42);
		// Print a line to the console
		System.out.println("moves to the next line automatically");
	}
}

print() vs println()

print() cursor को वहीं छोड़ता है जहां output खत्म हुआ, इसलिए एक दूसरी print() call उसी line पर जारी रहती है -- कई statements में एक line of output बनाने के लिए उपयोगी, println() के विपरीत।

उदाहरण: print() vs println()

java
public class Main {
	public static void main(String[] args) {
		System.out.print("Same ");
		System.out.print("line"); // continues right where the last print ended
	}
}

Concatenating Output

println() के अंदर + operator उपयोग करना, जैसे println("Score: " + score), non-string values को text में convert करता है और print करने से पहले उन्हें एक single string में जोड़ता है -- Java left से right evaluate करता है।

उदाहरण: Concatenating Output

java
public class Main {
	public static void main(String[] args) {
		int score = 90;
		System.out.println("Score: " + score); // non-string joined into one string
	}
}

Printing Expressions

Java parentheses के अंदर कोई भी arithmetic पहले compute करता है -- println(2 + 3) 5 print करता है, literal text "2 + 3" नहीं -- इसलिए एक line में math और string concatenation mix करने के लिए operator precedence के साथ care चाहिए।

उदाहरण: Printing Expressions

java
public class Main {
	public static void main(String[] args) {
		System.out.println(2 + 3); // prints 5, not the text "2 + 3"
	}
}

Special Escape Characters

\n (newline) और \t (tab) जैसे Escape sequences आपको कई print statements की ज़रूरत के बिना एक single string literal के अंदर spacing और line breaks control करने देते हैं।

उदाहरण: Special Escape Characters

java
// Define the class Main
public class Main {
	// Program entry point: the JVM starts running here
	public static void main(String[] args) {
		// Print a line to the console
		System.out.println("Line one\nLine two\tTabbed");
	}
}
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. print() उपयोग करना जब आप एक नई line चाहते हों, इसलिए अगली output उसी line पर दिखती है।
  2. किसी string के अंदर quotes escape करना भूल जाना, जैसे "He said "hi"", जो एक compile error है; \" उपयोग करें।
  3. System.out.println("a" + 1 + 2) लिखना और arithmetic की उम्मीद करना, जब numbers text के रूप में जुड़ते हैं।
🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.