-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4.5.java
More file actions
33 lines (31 loc) · 1003 Bytes
/
4.5.java
File metadata and controls
33 lines (31 loc) · 1003 Bytes
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
package example;
public class Class2{
public static void main(String[] argus)
{
String text = "To be or not to be.";
String reversetext="" ;
char ch = ' ';
int substr = 0;
int i=0, j=0, index=0;
System.out.println("Text before reversing : " + text);
for(i=0; i<text.length(); )
{
index = text.indexOf(ch,substr);
for(j=index-1; j>=substr; j--)
{
reversetext += text.charAt(j);
}
if(index != -1)
{
substr = index+1;
i= substr;
reversetext += " ";
}
else
break;
}
for(int n=text.length()-2; n>=substr; n--)
reversetext += text.charAt(n);
System.out.println("\nText after reversing : "+reversetext +".");
}
}