-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrename.java
More file actions
26 lines (17 loc) · 715 Bytes
/
rename.java
File metadata and controls
26 lines (17 loc) · 715 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
public class rename {
public int rename(String currentName, String newName) {
String [] SheetNames = {"sheet1", "sheet2", "sheet3", "sheet4"};
int currentNameindex = -1;
int i = 0;
for (i = 0; i < SheetNames.length; i++) {
if (currentNameindex < 0)// currentName has not been found yet
if (SheetNames[i].equals(currentName))
currentNameindex = i;
if (SheetNames[i].equals(newName)) // newName is found in the list
return -1;
}
if (currentNameindex > 0) // currentName is found in the list
SheetNames[currentNameindex] = newName; // rename the list item
return currentNameindex;
}
}