Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

V I N O T H
V I N O T H

Posted on

     

While loop task

Key words in While loop:

In a while loop, the key Java keywords and concepts used are:

while – This keyword is used to start a while loop. It repeatedly executes a block of code as long as the given condition is true.Loop Condition – The condition inside the parentheses (no1 < 10) determines if the loop should continue or stop.Loop Body – The block of code inside {} runs repeatedly while the condition is true.Loop Control Variable – A variable (no1 in your case) that changes inside the loop to eventually break the loop.Increment/Decrement Statement – no1++ increases the loop variable to prevent an infinite loop.Break Condition (Implicit) – The loop stops when the condition (no1 < 10) becomes false.System.out.println – Used inside the loop to print output during each iteration.
Enter fullscreen modeExit fullscreen mode

Task 1:

package loopingDemo;public class First_Looping {    public static void main(String[] args) {//       TODO Auto-generated method stub        int total=0;        int no1=0;        int no2=3;        while(no1<10) {            no1=no1+1;                  total=no1*no2;            System.out.println(no1+"*"+no2+"="+total);         }    }
Enter fullscreen modeExit fullscreen mode

Output

1*3=32*3=63*3=94*3=125*3=156*3=187*3=218*3=249*3=2710*3=30
Enter fullscreen modeExit fullscreen mode

Task 2:

package loopingDemo;public class First_Looping {    public static void main(String[] args) {int count=1;        while(count<=5) {            System.out.println("12345");            count++;        }       }}
Enter fullscreen modeExit fullscreen mode

Output

1234512345123451234512345
Enter fullscreen modeExit fullscreen mode

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

  • Joined

More fromV I N O T H

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp