-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModify Variable Name.txt
More file actions
42 lines (37 loc) · 915 Bytes
/
Modify Variable Name.txt
File metadata and controls
42 lines (37 loc) · 915 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
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public static String func(String input){
String res="";
char[] c=input.toCharArray();
if(input.contains("_")){
for(int i=0;i<c.length;i++){
if(c[i]!='_'){
if(i!=0 && c[i-1]=='_'){
res+=String.valueOf(c[i]).toUpperCase();
}else{
res+=c[i];
}
}
}
}else{
for(int i=0;i<c.length;i++){
if(String.valueOf(c[i]).equals(String.valueOf(c[i]).toUpperCase())){
res+="_"+String.valueOf(c[i]).toLowerCase();
}else{
res+=c[i];
}
}
}
return res;
}
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
System.out.println(func("modify_varaibleName"));
}
}