Java:-
i) Write a program in java to print zero '0' when user enters '1' and print '1' when user enters zero '0'. (Without if)
ii) Write a program to accept three colours of our national flag (not in chronological order) and display them in the way they appear in it one after another.
Answers
Explanation:
When reading the first numbers to populate large and small we only need to do that once. And without re-reading the numbers with in.nextInt() because that will eat up the next inputs that are entered, which was probably causing the not terminating at zero error.
while ((input = in.nextInt()) != 0) {
if (counter == 0)
small = large = input;
if (input != 0)
sum = input + sum;
counter++;
if (input > large)
large = input;
if (input < small)
small = input;
if (input % 2 == 0)
even = even + 1;
else
odd = odd + 1;
♡──━━━━━━⊱✿⊰━━━━━━──♡
Explanation:
The National Flag of India (Hindi: Tiraṅgā) is a horizontal rectangular tricolour of India saffron, white and India green; with the Ashoka Chakra, a 24-spoke wheel, in navy blue at its centre. It was adopted in its present form during a meeting of the Constituent Assembly held on 22 July 1947