-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.java
More file actions
61 lines (46 loc) · 1.3 KB
/
demo.java
File metadata and controls
61 lines (46 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import java.util.Scanner;
public class demo {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter your name: ");
String name = sc.nextLine();
System.out.println("Hello " + name);
}
}
/*
*
Question:
What will be the output of the following code?
java
Copy code
import java.util.Scanner;
public class demo {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter your name: ");
String name = sc.nextLine();
System.out.println("Hello " + name);
}
}
Approach:
Problem:
The problem is to take input from the user and greet them by their name.
Preface:
The program takes input from the user for their name and greets them using their name.
Logic:
Initialize a Scanner object to take input from the user.
Prompt the user to enter their name.
Read the name entered by the user.
Print a greeting message using the entered name.
Pseudocode:
1. Initialize Scanner object.
2. Prompt user to enter their name.
3. Read the entered name.
4. Print a greeting message using the entered name.
Time Complexity:
Input: O(1)
Output: O(1)
Total: O(1)
Output:
The program will prompt the user to enter their name and then greet them using their name.
*/