Question

In: Computer Science

Use Java to rewrite the following pseudo-code segment using a loop structure without goto, break, or...

Use Java to rewrite the following pseudo-code segment using a loop structure without goto, break, or any other unconditional branching statement:

k = (j+13)/27; //assume i,j,k are integers properly declared.

loop:

if k > 10 then goto out

k=k+1.2;

i=3*k-1;

goto loop;

out: …

Solutions

Expert Solution

public class TestLoop {
   public static void main(String[] args) {
       double j = 5, i = 0;
       double k = (j + 13) / 27.0; // assume i,j,k are integers properly
                                   // declared.

// loop untill k is <10 which replaces the go to statement

       while (k < 10) {
           k = k + 1.2;
           i = 3 * k - 1;
       }
       System.out.println(i);
       System.out.println(j);
       System.out.println(k);

   }

}


Related Solutions

4. Rewrite the following pseudocode segment using a loop structure in the specified languages: k =...
4. Rewrite the following pseudocode segment using a loop structure in the specified languages: k = (j + 13) / 27 loop:       if k > 10 then goto out       k = k + 1       i = 3 * k - 1       goto loop out: . . . a. C++ b. Python c. Ruby Assume all variables are integer type. Discuss the relative merits of the use of these languages for this particular code.
(This is for java) I need to rewrite this code that uses a while loop. public...
(This is for java) I need to rewrite this code that uses a while loop. public class Practice6 {      public static void main (String [] args) {         int sum = 2, i=2;        do { sum *= 6;    i++;    } while (i < 20); System.out.println("Total is: " + sum); }
Can you rewrite this MATLAB code using a for loop instead of a while loop? %formatting...
Can you rewrite this MATLAB code using a for loop instead of a while loop? %formatting clc, clear, format compact; %define variables k=1; b=-2; x=-1; y=-2; %while loop initialization for k <= 3 disp([num2str(k), ' ',num2str(b),' ',num2str(x),' ',num2str(y),]); y = x^2 -3; if y< b b = y; end x = x+1; k = k+1; end
USE GENERICS TO WRITE THE JAVA CODE FOR THIS ASSIGNMENT In this assignment, rewrite two of...
USE GENERICS TO WRITE THE JAVA CODE FOR THIS ASSIGNMENT In this assignment, rewrite two of the following sorting methods (Insertion Sort, Selection Sort, Quick Sort, and Merge Sort) to sort ArrayList of objects using Comaprable interface. (60 points)
Need this 8 queen code with same exact solution without goto. Need to keep the code...
Need this 8 queen code with same exact solution without goto. Need to keep the code as similar as possible. #include <iostream> #include <cmath> using namespace std; int main(){ int q[8], c = 0, i, j,count=0; q[0] = 0; //first queen top corner nc: c++; if(c == 8 ) goto print; q[c] = -1; nr: q[c]++; if(q[c] == 8) goto backtrack; for(i= 0; i < c; i++) { if((q[i] == q[c])||(c - i == abs(q[c] - q[i]))) goto nr; }...
Modify the following java code, utilizing a loop mechanism to enable the user to use the...
Modify the following java code, utilizing a loop mechanism to enable the user to use the calculator more than once. The program does the following:    It prompts the user to enter 2 numbers.    It prompts the user to choose an operation to perform on those numbers:    Operation 1: Addition.    Operation 2: Subtraction.    Operation 3: Multiplication.    Operation 4: Division.    It outputs the result of the operation.    It asks the user if they want...
JAVA CODE, USE FOR LOOP PLEASE Using the PurchaseDemo program and output as your guide, write...
JAVA CODE, USE FOR LOOP PLEASE Using the PurchaseDemo program and output as your guide, write a program that uses the Purchase class to set the following prices, and buy the number of items as indicated. Calculate the subtotals and total bill called total. Using the writeOutput() method display the subtotals as they are generated as in the PurchaseDemo program. Then print the total bill at the end Use the readInput() method for the following input data Oranges: 10 for...
Develop an algorithm for INSERTION SORT. Give the pseudo-code version. Convert your pseudo-code into a Java...
Develop an algorithm for INSERTION SORT. Give the pseudo-code version. Convert your pseudo-code into a Java program.
Using existing Stack Java Collection Framework, write Java Code segment to do the following.   You may...
Using existing Stack Java Collection Framework, write Java Code segment to do the following.   You may write this in jGrasp Create a Stack of String called, myStacks Read input from keyboard, 10 names and then add to myStacks As you remove each name out, you will print the name in uppercase along with a number of characters the name has in parenthesis. (one name per line).   e.g.     Kennedy (7) Using existing Stack Java Collection Framework, write Java Code segment to...
Re-write following while loop into Java statements that use a Do-while loop. Your final code should...
Re-write following while loop into Java statements that use a Do-while loop. Your final code should result in the same output as the original code below. int total = 0; while(total<100) { System.out.println("you can still buy for"+(100-total)+"Dollars"); total=total+5; }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT