java :
Given an int variable n that has been initialized to a positive
value and, in addition, int variables k and total that have already
been declared,
use a do...while loop to compute the sum of the cubes of the first
n whole numbers, and store this value in total.
Use no variables other than n, k, and total.
SumOfCubes.java:
public class SumOfCubes {
public static void main(String args[]) {
int n=10;//n is value for
which we need sum of cubes upto
int k=1,total=0;//k is used
for iteration and total to store the sum
do
{
total =
total + k*k*k;//calculating cube of number and adding it to
total
k++;
}
while(k<=n);
System.out.println(total);//print value of total
}
}
Output:
SumOfCubes.java:( value of n entered during run-time)
import java.util.*;
public class SumOfCubes {
public static void main(String args[]) {
Scanner in = new
Scanner(System.in);
int n=0;//n is value for which
we need sum of cubes upto
int k=1,total=0;//k is used
for iteration and total to store the sum
System.out.println("Enter
value of n:");//input given during run-time
n = in.nextInt();
do
{
total =
total + k*k*k;//calculating cube of number and adding it to
total
k++;
}
while(k<=n);
System.out.println(total);//print value of total
}
}
Output:
java : Given an int variable n that has been initialized to a positive value and,...
Given an int variable k that has already been declared, use a while loop to print a single line consisting of 97 asterisks. Use no variables other than k. PLEASE ANSWER IN C
assume that input is an int array. the array is already declared and initialized wnd every element is assigned to an integer number. in addition assume that the array contains at least 1 element. write a code that contains one while loop abd no other loops to find both maximum and minimum numbers from input. then outout the maximum minus the minumum to the console window. (using java eclipse coding)
Convert the following while loop into a for loop. int 1 - 50: int sum-07 while (sum < 1000) sum - sum + 1; Question 35 (2 points) Saved Given an int variable k that has already been declared, use a while loop to print a single line consisting of 80 dollar signs. Use no variables other than k. int sum = 0; for(int i = 100;sum < 10000;1-- sum = sum + i;
In C An array ints of integers has already been declared and initialized. A function printint has been defined with the following prototype: void printint(int *); Write code that will call printint with a pointer to the second value in the array ints. Note: you will not need to declare an int variable.
anslate Assume that number is an int variable that has already been initialized. Write a statement that prints out the value of number in a field of 10 positions (right-justified within that field). Hint: Assume #include <iomanip> is included in the program. В І ЦА HTML Editor I 5 7 7 7 7 x x = = 1:12pt Paragraf O words 18 ctv A
Given an int variable n that has already been declared, write some code in C that repeatedly reads a value into n until at last a number between 1 and 10 (inclusive) has been entered.
Need some guidance with the following problems as I am new to Java programming. Any assistance is greatly appreciated. Thanks Using printf and specifiers for all print instructions: 1. Code the following: a. 10% is stored in a variable called discount when the customer is a student; otherwise, it stores 0%. Code this if … else control structure using the conditional operator (ternary operator). The variables discount and student have already been declared. Assume student is a boolean variable. b. ...
Java questions Part 1 Express the code fragment shown below using only a for loop. int n = 0; while (n <= 100) { int sum = sum + n; n = n + 1; System.out.println (sum); } Part 2 Use a loop structure to determine and print all positive integers between 1 and 100 that are divisible (evenly) by 5 and 8
using Java The formula to compute the volume of a sphere is: volume = ( 4 3 ) π r 3 where r is the radius of the sphere and π is 3.14159. Assume a variable radius has already been declared (type double) and initialized with the value of the radius of a sphere. Write java statements to do the following: Declare a constant PI and initialize it to 3.14159 Declare a variable volume of type double Calculate the volume...
Assume the following declarations have been made in main(): int howmany; Scanner kb = new Scanner(System.in); Random r = new Random(); Write code to do the following: Use a while loop to prompt the user for how many numbers are to be entered. If the user does not enter a positive number (a number greater than 0), display a message saying the number must be positive and to try again. Store this value in the howmany variable. Declare an integer...