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.
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 YOU
NOTE : PLEASE LIKE THE ANSWER.
IF YOU ARE SATISFIED WITH MY ANSWER,THANK YOU
programming in JAVA,,, Using 'while' loop write a snippet of code that would print on one...
Write a section of Java code using while, do-while and for loops Write a section of Java code that will print out random integers between 1 and 100 while N is less than or equal to 5. Sample output > random # 1 is: 73 random # 2 is: 68 random # 3 is: 76 random # 4 is: 64
java programming!!!
Write the code fragment that will do the following: • Ask the user how many numbers they want to enter • Declare and instantiate an array of doubles with as many elements as the number entered by the user • Write one 'for' loop to fill the array with data from the user • Write a second 'for' loop to calculate the sum of all of the numbers in the array • Print the calculated sum Note: Write...
Python programming: Write a while loop that prints a. All squares less than n. For example, if n is 100, print 0 1 4 9 16 25 36 49 64 81. b. All positive numbers that are divisible by 10 and less than n. For example, if n is 100, print 10 20 30 40 50 60 70 80 90 c. All powers of two less than n. For example, if n is 100, print 1 2 4 8 16...
Write Java code using a for loop that is equivalent to the following do-while loop: int i = 2 ; do { System.out.println(i + " squared is " + (i * i)) ; i += 2 ; } while (i <= 10) ;
Answer using programming in C only.
6 pts Use a while loop to complete the following: Prompt the user to enter integers one by one, until the user enters a negative number to stop Calculate the sum and the average of all the numbers entered by the user Print the sum and the average onto the screen after the loop. Declare and initialize all variables. Be sure to keep a count of the numbers entered for the average calculation
Write a JAVA code snippet which prints out numbers between 0 and 1,000,000, BUT only print the numbers which are a multiple of 3.
1. Write a code snippet Write a code snippet that asks the user to enter a name and a major one at a time and creates a dictionary with keys corresponding to names and values corresponding to majors. Assume that the user enters “alice”, “bio”, “mark”, “engineering”. >>>d = {} >>> your code starts here 2.Based on your code above: >>> print(d) 3.Write a code snippet Write a code snippet that creates a dictionary (records) using keys from a frozenset...
Complete the following code snippet using java so that it finds the sum of doubles the user inputs. Your answer should be a while loop with a condition that needs to be true if the user inputs a double. Your answer should be a single while loop. Scanner scnr = new Scanner(System.in); int sum = 0;
17. (2 points) C++ Using a while loop, write the code statements to sum 10 integers entered by a user. Display the sum. Hint: Be sure to declare, initialize, and use appropriate variables to count the repetitions and accumulate the sum.
please write c programming for this code below.
Write a program to print a pattern of numbers separated by spaces for the given number of rows. At the time of execution, the program should print the message on the console as: Enter number of rows For example, if the user gives the input as: Enter number of rows : 4 then the program should print the result as: 232 34543 4567654