-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZoho31.java
More file actions
64 lines (57 loc) · 1.25 KB
/
Copy pathZoho31.java
File metadata and controls
64 lines (57 loc) · 1.25 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
60
61
62
63
64
import java.util.*;
import java.io.*;
class Zoho31
{
static void splitString(String str)
{
int c_flag = 0,n_flag = 0,count = 0;
String res = new String();
StringBuffer alpha = new StringBuffer();
int num=0;
for (int i=0; i<str.length(); i++)
{
if(Character.isAlphabetic(str.charAt(i)))
{
alpha.append(str.charAt(i));
c_flag = 1;
}
else if(Character.isDigit(str.charAt(i)))
{
num = (int)(str.charAt(i)) - 48;
n_flag = 1;
while(((i+1)!= str.length())&& Character.isDigit(str.charAt(i+1)))
{
i=i+1;
num = num * 10;
num = num + ((int)str.charAt(i)-48);
}
}
else {
continue;
}
if(c_flag == 1 && n_flag == 1)
{
for(int j=0;j<num; j++)
{
res = res + alpha ;
}
c_flag =0;
n_flag=0;
}
if(c_flag == 0 && n_flag ==0)
{
alpha.delete(0,alpha.length());
num = 0;
}
}
System.out.println(res);
}
// Driver method
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the expression : " );
String str = sc.next();
splitString(str);
}
}