Professional Documents
Culture Documents
/
SEM-5-CSE
Code Issues Pull requests Discussions Actions Projects Wiki Security Insights
Code Blame
1 /**
2 Write a Java program to input user's name and greet the user as stated in the example.
3 Study the given partial code, fill-in the required code and apply your understanding in solving the next problem.
4
5 Ensure to declare the main class as public. Obviously, main class is the class with main() method.
6
7 Input
8 Mr. James Gosling
9
10 Result
11 Hello Mr. James Gosling!
12
13 */
14
15 import java.util.Scanner;
16 public class Hello {
17 public static void main(String args[]) {
18 /* Create Scanner object for reading from keyboard */
19 Scanner sc = new Scanner(System.in);
20
21 /* Use nextLine() for string input and nextInt() for integer input */
22 String name = sc.nextLine();
23
24 /* Use + operator for concatenation */
25 System.out.println("Hello " + name + "!");
26
27 /* Close the Scanner object */
28 sc.close();
29 }
30 }