public class Main { public static void main(String args[]) { System.out.print("Hello World "); System.out.println("Hello Know Program"); }}
Question
Question
public class Main {
public static void main(String args[]) {
System.out.print("Hello World ");
System.out.println("Hello Know Program");
}
}
Solution
This is a simple Java program. Here's a step-by-step explanation:
-
public class Main {
: This line is defining a new public class named Main. In Java, every application must contain a main class that wraps up all the code. -
public static void main(String args[]) {
: This line is defining the main method. This is the entry point for any Java application. The Java Virtual Machine (JVM) calls the main method when the program starts. TheString args[]
parameter is an array of String objects which contains command line arguments. -
System.out.print("Hello World ");
: This line is using theprint
method ofSystem.out
object to print the string "Hello World " to the console. Theprint
method does not add a new line character at the end, so any following output will be printed on the same line. -
System.out.println("Hello Know Program");
: This line is using theprintln
method ofSystem.out
object to print the string "Hello Know Program" to the console. Theprintln
method adds a new line character at the end, so any following output will be printed on a new line. -
}}
: These are closing braces for the main method and the Main class.
When this program is run, it will output:
Hello World Hello Know Program
Similar Questions
public class Example {public static void main(String[] args) {String str = "Hello";str.concat(" World");System.out.println(str);}}
class Test { public static void main(String args[]) { System.out.println(fun()); } static int fun() { static int x= 0; return ++x; }}
What will the following print out?String shout = "hello";shout = shout.toUpperCase();System.out.println(shout);Group of answer choicesHELLO
What is the output of the following code snippet? String str1 = "Java"; String str2 = new String("Java"); System.out.println(str1 == str2);
What will be the output of the program?String s = "ABC"; s.toLowerCase(); s += "def"; System.out.println(s);ABCabcABCdefCompile Error
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.