How to get Output ? How to write output program ? (ch 02)
Chapter 2 :- Output
Output Syntax :- System.out.println("Hello World");
In java, these syntax is very case sensitive. If you had some mistake in uppercase or lowercase characters then it throws an error. This need to write the exact code.
Inside the ("_")quotation we can write our output, In syntax we write "Hello World" if you need some other output, then you can put inside the quotation.
In that syntax the println is for print new line, the 'ln' is for new line. If sometimes we need to write the code in same line then it is necessary to not to write 'ln'.
For ex :- System.out.print("Hello World");
Also the semicolon (;) after finishing the code it is also mendatory write, The semicolon shows that our program stops at that point or end of the line. Semicolon(;) is also called as Statement Terminator.
Now we can write our first java program, Write your first program with consentration because java is case sensitive.
Program :-
1)print :-
public class fileName{
public static void main(String[] args){
System.out.print("My name is Niraj! How are you?");
System.out.print("I'm fine");
}
}
give me the answer in comments.
2)println :-
This program is for new line :-
public class fileName{
public static void main(String[] args){
System.out.println("My name is Niraj! How are you?");
System.out.println("I'm fine");
System.out.println("Java is awesome!");
}
}
give me the answer in comments.
3) \n is also use for new line :-
public class fileName{
public static void main(String[] args){
System.out.print("My name is Niraj! How are you?");
System.out.print("I'm fine\n");
System.out.println("Java is awesome!");
}
}
give me the answer in comments.
Try this code on your code playground. after doing this your doubt has been solved about print and println.
This is my first java program, so you can also write your own program and practice this syntax. Before going to deep in programming you practice this code.
Comments
Post a Comment