-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathString_printX.java
More file actions
45 lines (39 loc) · 1.09 KB
/
String_printX.java
File metadata and controls
45 lines (39 loc) · 1.09 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
public class Test2 {
public static void main(String[] args) {
String s1="PROGRAM";
System.out.println(s1);
printX(s1);
}
public static void printX(String s){
for(int i=0;i<s.length();i++){
for(int j=0;j<s.length();j++){
if(s.substring(j).length()==(i+1) )
System.out.print(s.charAt(j)+"");
if(j==i && j!=(s.length()/2))
System.out.print(s.charAt(j)+"");
else
System.out.print(" ");
}
System.out.println(" ");
}
//Slight Modification
public static void printX(String s){
for(int i=0;i<s.length();i++){
for(int j=0;j<s.length();j++){
if(j==i || (s.substring(j).length()==i+1))
System.out.print(s.charAt(j)+"");
else
System.out.print(" ");
}
System.out.println(" ");
}
}
//output:
Program
P m
r a
o r
g
o r
r a
P m