Welcome to Java! Hackerrank Solution
java 7
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Print output to STDOUT. Your class should be named Solution. */
System.out.println("Hello, World.");
System.out.print("Hello, Java.");
}
}
java 8
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Print output to STDOUT. Your class should be named Solution. */
System.out.println("Hello, World.");
System.out.print("Hello, Java.");
}
}
java 15
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
System.out.println("Hello, World.");
System.out.print("Hello, Java.");
}
}
Code Explanation
The provided solutions are simple and straightforward. They all consist of a class named Solution with a main method. Inside the main method, the two required lines of code are present:
System.out.println("Hello, World."); prints "Hello, World." to the console.
System.out.println("Hello, Java."); prints "Hello, Java." to the console.
Both lines use the System.out.println() method to print the specified text followed by a newline character.