siva
BAN USER
Comments (2)
Reputation -5
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
static void diff(int n)
{
String s,c;
String s1=" ",s2=" ";
boolean flag=true;
for(int i=10;i<=n;i++)
{
// Convert the number to string
s=Integer.toString(i);
for(int j=0;j<s.length()-1;j++)
{
//For each number 0 to N compare the values of adjacent integer in N
c=String.valueOf(i);
s1=String.valueOf(c.charAt(j));
s2=String.valueOf(c.charAt(j+1));
if(Integer.parseInt(s1)==Integer.parseInt(s2)+1 || Integer.parseInt(s1)+1 == Integer.parseInt(s2))
{
flag=true;
continue;
}
else
{
flag=false;
break;
}
}
if(flag)
{
System.out.println(i);
}
}
}
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
Open Chat in New Window
Open Chat in New Window
- siva June 15, 2016