public class Main { public static void main(String args[]) { System.out.print("Hello World "); System.out.println("Hello Know Program"); }}
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 theprintmethod ofSystem.outobject to print the string "Hello World " to the console. Theprintmethod 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 theprintlnmethod ofSystem.outobject to print the string "Hello Know Program" to the console. Theprintlnmethod 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 Test { public void m1(String arg1) { arg1="Test"; } public static void main(String[] args) { Test test1= new Test(); String s= "Hello"; test1.m1(s); System.out.println(s); }}
Insert the missing part of the code below to output "Hello World".public class MyClass { public static void main(String[] args) { ..("Hello World"); }
What will be the output of the following program?class string_class {public static void main(String args[]){String obj = "hello";String obj1 = "world"; String obj2 = obj;obj2 = " world";System.out.println(obj + " " + obj2); }}
What is the output of the below program?public class Main{ public static void main(String[] args) { int a = 25; if(a > 5) System.out.print("Hi "); if(a < 20) System.out.print("Hello "); else System.out.print("Know Program "); }}
e correct answerWhat is the output of the following Java program?class Main { public static void main(String args[]) { final int i; i = 20; i = 30; System.out.println(i); }}
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.