-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReversedString.java
More file actions
47 lines (39 loc) · 977 Bytes
/
ReversedString.java
File metadata and controls
47 lines (39 loc) · 977 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package prg.es4;
import java.lang.CharSequence;
public class ReversedString implements CharSequence{
private String reversedString;
//COSTRUTTORE
private ReversedString(){
this.reversedString = "";
}
public ReversedString(String string){
this.reversedString = "";
for(int i = string.length()-1; i >= 0; i--){
this.reversedString += string.charAt(i);
}
}
//METODI
public char charAt(int index){
if(index < this.length()){
return this.reversedString.charAt(index);
} else {
System.out.println("Errore!");
return ' ';
}
}
public int length(){
return this.reversedString.length();
}
public CharSequence subSequence(int start, int end){
ReversedString res = new ReversedString();
if(start <= end){
for(int i = start; i <= end; i++){
res.reversedString += this.reversedString.charAt(i);
}
}
return res;
}
public String toString(){
return this.reversedString;
}
}