Answers for "insert * if subsequent number even - if odd"

0

insert * if subsequent number even - if odd

public class InsertStarBetweenEvenAndDashBetweenOdd {

	public static void main(String[] args) 
	{
		long l=104875l;
		
		String s= ""+l;
		StringBuilder s2= new StringBuilder("");
		s2.append(s.charAt(0));
		
		for(int i=1;i<s.length();i++)
		{
			int t1= Integer.parseInt(s.charAt(i-1)+"");
			int t2= Integer.parseInt(s.charAt(i)+"");
			s2.append((t1%2==0?(t2%2==0?"*"+s.charAt(i):s.charAt(i)):(t2%2!=0?"-"+s.charAt(i):s.charAt(i)))+"");
			
		}
		System.out.println(s2.toString());

	}

}
Posted by: Guest on June-01-2021

Code answers related to "insert * if subsequent number even - if odd"

Browse Popular Code Answers by Language