Ask Question
9 July, 03:34

Suppose that the code below is the body of some loop. Given variables x and y write some code that reads a value into the variables, respectively, then prints out the value of x divided by y. Use a continue statement to make sure that nothing is written to court when y is 0.

+1
Answers (1)
  1. 9 July, 04:36
    0
    I will code in JAVA.

    import java. util. Scanner;

    public class Main {

    public static void main (String[] args) {

    float x;

    float y;

    float result;

    Scanner input = new Scanner (System. in);

    while (true) { / /this is an infinite loop

    x = input. nextFloat (); / /wait the input for x

    y = input. nextFloat (); / /wait the input for y

    if (y = = 0) {

    continue; / /next iteration without print.

    } else{

    result = x/y;

    System. out. print (result); / /print the result.

    }

    }

    }

    }

    Explanation:

    To get the numbers, you need to import Scanner class, and use the method nextFloat () to admit floats and integers.

    If y is 0 then, executes the continue statement, if not prints the division between x and y.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Suppose that the code below is the body of some loop. Given variables x and y write some code that reads a value into the variables, ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers