Scanner sc = new Scanner(System.in);
String s = sc.nextLine().trim();
s= s.replaceAll("\\++"," + ");
Pattern p = Pattern.compile("[a-zA-Z]+|\\d+|[\\(\\*\\)/%]");
Matcher m = p.matcher(s);
while(m.find()){
String str=m.group();
s= s.replace(m.group()," "+str+" ").trim();
}
String[] str=s.split(" +");
for(String s1:str) System.out.print(s1+",");
if s=22*(7-9
output is: 22,*,(,7,-,9,
if s=12*(4-2
output is:1,2,*,(,4,-,2,
Why digits of 12 got separated in second example? Help me if someone knows about it