-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChange.java
More file actions
59 lines (57 loc) · 1.57 KB
/
Change.java
File metadata and controls
59 lines (57 loc) · 1.57 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Program: Convert Case of Characters Using Recursion
// Topic: Recursion and String Manipulation
// Description: Reads a word from user input and recursively converts each character’s case —
// uppercase to lowercase and vice versa — using a recursive function `recchange()`.
// Demonstrates base and recursive conditions, ASCII-based case conversion, and recursive string construction.
package recursion;
import java.util.*;
/**
*
* @author Samim
*/
public class Change {
String str;
String newstr;
int len;
public Change() {
str="";
newstr="";
len=0;
}
void inputword(){
Scanner sc=new Scanner(System.in);
System.out.println("Enter The Word :");
str=sc.next();
len=str.length();
}
char caseconver(char ch){
int asc=(int)ch;
if(asc>=65 && asc<=90){
return (char)(ch+32);
}
else if(asc>=97 && asc<=122){
return (char)(ch-32);
}
else return ch;
}
void recchange(int n){
System.out.println(n);
if(n==len){
return ;
}
else{
newstr=newstr+caseconver(str.charAt(n));
recchange(n+1);
}
}
void display(){
System.out.println("String :"+str);
System.out.println("New String :"+newstr);
}
public static void main(String[] args){
Change obj=new Change();
obj.inputword();
obj.recchange(0);
obj.display();
}
}