Tuesday, January 9, 2018

Solution assignment 002

public class SolutionLoop2
{
public static void main(String[] args)
{
int start = 10;
int end = 20;
int number = 1;
int choice = 0;
int flag = 0;
int counter = 0;

System.out.println("## Numbers from "+start+" to "+end+" are =>");
for(int i = start; i <= end; i++)
{
for(int j = i; j != 0; j = j / 10)
{
int temp = j % 10;
if(temp == number)
{
flag = 1;
}
}
if(flag == choice)
{
System.out.println(i);
counter++;
}
flag = 0;
}
System.out.println("## From "+start+" to "+end+" total numbers are "+counter);
}
}

No comments:

Post a Comment