Computer Applications

Write a program to display all the numbers between 100 and 200 which don't contain zeros at any position.
For example: 111, 112, 113, ……. , 199

Java

Java Nested for Loops

40 Likes

Answer

public class KboatNoZero
{
    public void display() {
        
        int count = 0;
        for (int i = 100; i <= 200; i++) {
            
            boolean isNoZero = true;
            int t = i;
            while (t > 0) {
                if (t % 10 == 0) {
                    isNoZero = false;
                    break;
                }
                
                t /= 10;
            }
            
            if (isNoZero) {
                System.out.print(i + " ");
                count++;
            }
            
            //This will print 10 numbers per line
            if (count == 10) {
                System.out.println();
                count = 0;
            }
        }
        
    }
}

Variable Description Table

Program Explanation

Output

Answered By

15 Likes


Related Questions