KnowledgeBoat Logo
|

Computer Applications

In a competitive examination, a set of 'N' number of questions results in 'True' or 'False'. Write a program by using scanner class to accept the answers. Print the frequency of 'True' and 'False'.

Java

Input in Java

8 Likes

Answer

import java.util.Scanner;

public class KboatCompetitiveExam
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter number of questions: ");
        int n = in.nextInt();
        int trueFreq = 0, falseFreq = 0;
        System.out.println("Enter answers:");
        for (int i = 1; i <= n; i++) {
            boolean ans = in.nextBoolean();
            if (ans)
                trueFreq++;
            else
                falseFreq++;
        }
        System.out.println("True Frequency = " + trueFreq);
        System.out.println("False Frequency = " + falseFreq);
    }
}

Variable Description Table

Program Explanation

Output

BlueJ output of In a competitive examination, a set of 'N' number of questions results in 'True' or 'False'. Write a program by using scanner class to accept the answers. Print the frequency of 'True' and 'False'.

Answered By

2 Likes


Related Questions