24.3k views
5 votes
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) ;

1 Answer

4 votes

Answer:

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.
User Peter Lindqvist
by
4.5k points