13 June 2018
Secure the given valid id's by making 1st 9 digit as *(star)
valid id is identified by following condition.
1) Even places of a number sum is greater than the odd places sum.
2)It's consists of 13 digit
i/p:
1234567890123
o/p:
*********0123
import java.util.*;
public class NewClass12 {
void print(String k)
{
System.out.println(k);
}
String secure(String s)
{
char c[]=s.toCharArray();
int odd=0,even=0;
for(int i=0;i<c.length;i++)
{
if(i%2==0)
{
even+=(c[i]-'0');
}else
{
odd+=(c[i]-'0');
}
}
if(even>odd)
{
for(int i=0;i<9;i++)
c[i]='*';
}
return String.valueOf(c);
}
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
String k=s.nextLine();
NewClass12 ob=new NewClass12();
if(k.length()==13)
{
k=ob.secure(k);
}
ob.print(k);
}
}
Labels:
String
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment