-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAlternate.java
53 lines (53 loc) · 1.29 KB
/
Alternate.java
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
48
49
50
51
52
53
package Programs;
import java.util.*;
class Alternate{
private String str;
private String newStr;
private int len;
Alternate(){
newStr=str="";
len=0;
}
void readWord(){
Scanner sc=new Scanner(System.in);
System.out.println("Enter the word");
str=new Scanner(System.in).nextLine();
}
void change(){
int p=0;
newStr=""+(str.charAt(0));
if(Character.isUpperCase(str.charAt(0)))
p=1;
else
p=2;
if(p==1){
for(int i=1;i<str.length();i++){
char z=str.charAt(i);
if(i%2!=0)
newStr+=(Character.toLowerCase(z));
else
newStr+=(Character.toUpperCase(z));
}
}
else
{
for(int i=1;i<str.length();i++){
char z=str.charAt(i);
if(i%2!=0)
newStr+=(Character.toUpperCase(z));
else
newStr+=(Character.toLowerCase(z));
}
}
}
void display(){
System.out.println("ORIGINAL WORD: "+str);
System.out.println("NEW WORD: "+newStr);
}
public static void main(String args[]){
Alternate ob= new Alternate();
ob.readWord();
ob.change();
ob.display();
}
}