DEV Community

Guna Sekaran
Guna Sekaran

Posted on

2

while loop in java

package ifelse;

public class Thenaliraman {
   public static void main(String[] args) {
    int whip_bit=1024;
    int count=0;
while(whip_bit>1) {
    whip_bit=whip_bit/2;
    count++;
    System.out.println( whip_bit);

}
System.out.println("total person:" + count);

}
}

//output:
512
256
128
64
32
16
8
4
2
1
total person:10







Enter fullscreen mode Exit fullscreen mode
package ifelse;
public class Number {
    public static void main(String[] args) {
        int a = 3;
        int count = 1;

        while (count <= 10) {
            int b =count * a;
            System.out.println(count + " * " + a + " = " +b);
            count=count+1;
        }
    }
}

output:
   1 * 3 = 3
2 * 3 = 6
3 * 3 = 9
4 * 3 = 12
5 * 3 = 15
6 * 3 = 18
7 * 3 = 21
8 * 3 = 24
9 * 3 = 27
10 * 3 = 30


Enter fullscreen mode Exit fullscreen mode
package ifelse;

public class Number1 {
    public static void main(String[] args) {
        int a=100;
        int b=120;
        int count=1;
    while(count<=a && count<=b) {
        if(a%count==0 && b%count==0) {
        System.out.println("common divisible numbers:"+ count);
        }
        count++;
    }
    }


    }


     output:

          common divisible numbers:1
          common divisible numbers:2
          common divisible numbers:4
          common divisible numbers:5
          common divisible numbers:10
          common divisible numbers:20


Enter fullscreen mode Exit fullscreen mode

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (0)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay