DEV Community

Pavithra C
Pavithra C

Posted on

Day:37-While loop practice 3

Example1:

package While;

public class Police { 
    public static void main(String[] args) {
        int police=0;
        int thief=40;

        while(police<thief) {
            thief=thief+3;
            police=police+5;

        }
        System.out.println(police);     
    } 

}
Enter fullscreen mode Exit fullscreen mode

Output:
100

Example2:

package While;

public class Wrapper {

    public static void main(String[] args) {
        int choco=15;
        int wrapper=15;

        while(wrapper>=3) {
            wrapper= wrapper-3;
            choco=choco+1;
            wrapper=wrapper+1;
        }
        System.out.println(choco);
    }

}

Enter fullscreen mode Exit fullscreen mode

Output:
22

Top comments (0)