0 votes
in JAVA by
What will be the output of the following program?

public class Test {  

public static void main(String[] args) {  

    int count = 1;  

    while (count <= 15) {  

    System.out.println(count % 2 == 1 ? "***" : "+++++");  

    ++count;  

        }      // end while  

    }       // end main   

 }  

i) 15 times ***

ii) 15 times +++++

iii) 8 times *** and 7 times +++++

iv) Both will print only once

1 Answer

0 votes
by

iii) 8 times *** and 7 times +++++

Reason: In the above code, we have declared count = 1. The value of count will be increased till 14 because of the while (count<=15) statement. If the remainder is equal to 1 on dividing the count by 2, it will print (***) else print (+++++). Therefore, for all odd numbers till 15 (1, 3, 5, 7, 9, 11, 13, 15), it will print (***), and for all even numbers till 14 (2, 4, 6, 8, 10, 12, 14) it will print (+++++).

Related questions

0 votes
asked Apr 10, 2021 in JAVA by Robindeniel
0 votes
asked Apr 10, 2021 in JAVA by Robindeniel
...