Question

programming in JAVA,,, Using 'while' loop write a snippet of code that would print on one...

programming in JAVA,,,

Using 'while' loop write a snippet of code that would print on one line all powers of 2 that are less than 5000 separated by spaces. Declare all variables that you might need.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

source code in java :

import java.util.*;
import java.io.*;

public class Main
{
public static void main(String[] args) {
int i=1;
int pow = 1;
while(pow<5000)
{
pow = i*i;
//if the value of pow is greater than 5000 the loop terminates and the program will terminate...
if(pow>5000)
{
break;
}
// print is used to display in one line
System.out.print(pow+" ");
//The value of i will be incremneting for every exceution of loop
i=i+1;
}

}
}

NOTE : PLEASE LIKE THE ANSWER. IF YOU ARE SATISFIED WITH MY ANSWER,THANK YOUNOTE : PLEASE LIKE THE ANSWER. IF YOU ARE SATISFIED WITH MY ANSWER,THANK YOU

Add a comment
Know the answer?
Add Answer to:
programming in JAVA,,, Using 'while' loop write a snippet of code that would print on one...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT