Write a java program to input the c
Answers
Answer:
...........................................
Answer:
Java Output
In Java, you can simply use
System.out.println(); or
System.out.print(); or
System.out.printf();
to send output to standard output (screen).
Here,
System is a class
out is a public static field: it accepts output data.
Don't worry if you don't understand it. We will discuss class, public, and static in later chapters.
Let's take an example to output a line.
class AssignmentOperator {
public static void main(String[] args) {
System.out.println("Java programming is interesting.");
}
}
Output:
Java programming is interesting.
Here, we have used the println() method to display the string.
Difference between println(), print() and printf()
print() - It prints string inside the quotes.
println() - It prints string inside the quotes similar like print() method. Then the cursor moves to the beginning of the next line.
printf() - It provides string formatting (similar to printf in C/C++ programming).
Example: print() and println()
class Output {
public static void main(String[] args) {
System.out.println("1. println ");
System.out.println("2. println ");
System.out.print("1. print ");
System.out.print("2. print");
}
}
Output:
1. println
2. println
1. print 2. print
In the above example, we have shown the working of the print() and printf() methods. To learn about the printf() method, visit Java printf().
Example: Printing Variables and Literals
class Variables {
public static void main(String[] args) {
Double number = -10.6;
System.out.println(5);
System.out.println(number);
}
}
When you run the program, the output will be:
5
-10.6
Here, you can see that we have not used the quotation marks. It is because to display integers, variables and so on, we don't use quotation marks.
Example: Print Concatenated Strings
class PrintVariables {
public static void main(String[] args) {
Double number = -10.6;
System.out.println("I am " + "awesome.");
System.out.println("Number = " + number);
}
}
Output:
I am awesome.
Number = -10.6
In the above example, notice the line,
System.out.println("I am " + "awesome