I have coded as instructed in the question.
a.
int n=1; while(n<=max) { System.out.println(n); n++; }
b.
int total=25; int number=1; while(number<=(total/2)) { total=total-number; System.out.println(total + " " + number); number++; }
c.
int i=1; while(i<=2) { int j=1; while(j<=3) { int k=1; while(k<=4) { System.out.print("*"); k++; } System.out.print("!"); j++; } System.out.println(); i++; }
d.
int number=4; int count=1; while(count<=number) { System.out.println(number); number=number/2; count++; }
If my answer helped you then please upvote.Thank you.
[Textbook Chapter 5 Self-Check Problems: Question 2] Convert each of the following for loops into an...
c++ convert do while loop below to a for loop
#define MAX VALUE 5 #define START VALUE 5 //START_VALUE always <-MAX VALUE int main() convert do while loop below to a for loop int j - MAX VALUE; do cout <<<<endl; ; while > 0); I
Provide a "big oh" run-time analysis for each of the following.
When a value of “n” is used, it is the size of the input.
4.) void problem 40 cin n min max for (int i min i n, i++) for (int j- 1: j< max, j++) tota while (total n tota total 2 total 5.) void problem 50 cin n; for (int i 0: i n, i++) for (int j 0; j i2; j++) for (int k 0; k...
Q. 07 (2 points) Convert the following while loop to a for loop: int count = 0; while (count<50) cout<<"count iscounts endl count+
check) Determine the value in total after each of the following loops is executed for (i=i; i <-10; i-i+1) 3. (Desk a. total o total- total + 1i b. total 1; for (count 1; count <- 10, count count + 1) total = total * 2; c. total-0 for (i10; i 15: i i+ 1) total total ii d. total = 50; for (i -1: i <10; i i + 1) total = total - i; e. totall; for (icnt...
I am in an entry-level Java class and need assistance solving
questions 20-25 for a homework assignment. Any help is appreciated.
Thank you.
Q20 Read the code and answer the question 6 Points Read each of the following code snippets and determine if they are equivalent. I.e. they produce the same output. Q20.1 Are these snippets equivalent? 2 Points Snippet 1: int i=0; while (i<10) System.cut.print(i); i++; 1 Snippet 2: for(int i-0; i<10; i++) System.out.print(i); } Yes O No Q20.2...
Give a big-Oh characterization, in terms of n,of the running time for each of the following code segments (use the drop-down): - public void func1(int n) { A. @(1). for (int i = n; i > 0; i--) { System.out.println(i); B. follogn). for (int j = 0; j <i; j++) System.out.println(j); c.e(n). System.out.println("Goodbye!"); D.@(nlogn). E.e(n). F.ein). public void func2 (int n) { for (int m=1; m <= n; m++) { system.out.println (m); i = n; while (i >0){ system.out.println(i); i...
Prove Big O in terms of nₒ and C? There are 5 examples: class Exercise { public static int example1(int[] arr) { int n = arr.length, total = 0; for (int j=0; j < n; j++) // loop from 0 to n-1 total += arr[j]; return total; } public static int example2(int[] arr) { int n = arr.length, total = 0; for (int j=0; j < n; j += 2) // note the increment of 2 total += arr[j]; return...
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;
Why is my multiplication wrong when i do a matrix of 3 x 5 and 2
x 2?
code below
import java.util.*;
public class matrix {
public static
void main(String[] args) {
int m, n, i, j;
Random rand = new Random();
Scanner scan = new
Scanner(System.in);
System.out.print("enter how many
rows:");
m = scan.nextInt();
System.out.print("enter how many
columns:");
n=scan.nextInt();
int matrix_1[][] = new
int[m][n]; //Initialize matrixes
int maritx_2[][] = new
int[m][n];
int matrix_add[][] = new
int[m][n];
int matrix_mul[][] = new...
convert C to LEGv8
(an example given below)
Q1 [15] Convert the following C code to LEG. Assume the following variable/register assignments: Base of A i X19 X20 int main { long long int A[6] = {1, 2, e, e, e, e}; for unsigned int i = 0; i < { A[i+2] myFunction (A[ i] , A[i+1] ); } return 0 } 4; i+ //convert to LEG //convert to LEG //convert the entire myFunction to LEG long long int myFunction...