Ask Question
29 September, 16:27

what is the output after the following loop terminates? A int number = 25 int i; B. boolean isprime = true; C. for (i=2; i< number && isprime; i++) { if (number % i = = 0) { isprime = false; }} D. system. out. println ("i is " + i + " isprime is" + isprime);

+4
Answers (1)
  1. 29 September, 16:45
    0
    The output of the given program as follows:

    Output:

    i is 6 isprime is false

    Explanation:

    In the given program code there is some typing mistake so the correct program to this question as follows:

    Program:

    public class check / /defining class check

    {

    public static void main (String[] args) / /defining main method

    {

    int number = 25, i, j; / /defining integer variable

    boolean isprime = true; / /defining boolean variable

    for (i=2; i< number && isprime; i++) / /defining loop count numbers

    {

    if (number % i = = 0) / /if block for check condition

    {

    isprime = false; / /assing value flase in isprime variable

    }

    }

    System. out. println ("i is " + i + " isprime is " + isprime); / /print value

    }

    }

    Description of the above code as follows:

    In the above java code, a class "checks" are defined, inside this class main method is declared, in the main function 2 integer variable "number and i" is defined, in which number holds a value that is "25" and variable "i" is used in the for loop.

    In the next step for loop is defined, that starts from 2 and end when i is less then number and boolean variable, inside the loop if block is used, that check number modules value is equal to 0. If this condition is true in the isprime variable assign a false value, and outside the loop, the print function is used that print isprime variable value.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “what is the output after the following loop terminates? A int number = 25 int i; B. boolean isprime = true; C. for (i=2; i< number && ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers