-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPractical_10.java
More file actions
43 lines (40 loc) · 1.15 KB
/
Practical_10.java
File metadata and controls
43 lines (40 loc) · 1.15 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
/* Question := Write an interactive program to print a string entered in a pyramid. For instance, the
string “stream” has to be displayed as follows:
S
S t
S t r
S t r e
S t r e a
S t r e a m */
import java.util.Scanner;
public class Practical_10 {
public static void pattern(String s) {
for (int i=0; i<s.length(); i++) {
for(int j=s.length()-i; j>0; j--){
System.out.print(" ");
}
for(int j=0; j<i+1; j++){
System.out.print(s.charAt(j) + " ");
}
System.out.println();
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a String := ");
String s = sc.nextLine();
pattern(s);
}
}
/* Output :=
Enter a String :=
Vadodara
V
V a
V a d
V a d o
V a d o d
V a d o d a
V a d o d a r
V a d o d a r a
*/