Skip to content

Commit 05e6331

Browse files
committed
solition of string based problem
0 parents  commit 05e6331

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

One.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//reversing the order of terms of an algebraic expression that contains only 4 basic math operators without changing the order and the number itself e.g for input "5+6*7-60" output should be "60-7*6+5"
2+
3+
class One
4+
{
5+
public static void main(String args[])
6+
{
7+
8+
String str=args[0];
9+
String reverse="";
10+
11+
int pos=str.length()-1;
12+
13+
String term="";
14+
15+
for(int k=0;k<str.length();k++)
16+
{
17+
char ch=str.charAt(pos--);
18+
19+
switch(ch)
20+
{
21+
case '-':
22+
case '+':
23+
case '/':
24+
case '*':
25+
reverse=reverse+term+ch;
26+
term="";
27+
break;
28+
default:
29+
term=ch+term;
30+
}
31+
32+
}
33+
34+
System.out.println("reverse is "+(reverse+term));
35+
}
36+
37+
}

0 commit comments

Comments
 (0)