KnowledgeBoat Logo

Computer Applications

The equivalent resistance of series and parallel connections of two resistances are given by the formula:

(a) R1 = r1 + r2 (Series)

(b) R2 = (r1 * r2) / (r1 + r2) (Parallel)

Using a switch case statement, write a program to enter the value of r1 and r2. Calculate and display the equivalent resistances accordingly.

Java

Java Conditional Stmts

114 Likes

Answer

import java.util.Scanner;

public class KboatResistance
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.println("1. Series");
        System.out.println("2. Parallel");
        
        System.out.print("Enter your choice: ");
        int choice = in.nextInt();
        boolean isChoiceValid = true;
        
        System.out.print("Enter r1: ");
        double r1 = in.nextDouble();
        System.out.print("Enter r2: ");
        double r2 = in.nextDouble();
        double eqr = 0.0; 
        
        switch (choice) {
            case 1:
                eqr = r1 + r2;
                break;
            case 2:
                eqr = (r1 * r2) / (r1 + r2);
                break;
            default:
                isChoiceValid = false;
                System.out.println("Incorrect choice");
                break;
        }
        
        if (isChoiceValid)
            System.out.println("Equivalent resistance = " + eqr);
    }
}

Variable Description Table

Program Explanation

Output

BlueJ output of The equivalent resistance of series and parallel connections of two resistances are given by the formula: (a) R 1 = r 1 + r 2 (Series) (b) R 2 = (r 1 * r 2 ) / (r 1 + r 2 ) (Parallel) Using a switch case statement, write a program to enter the value of r 1 and r 2 . Calculate and display the equivalent resistances accordingly.BlueJ output of The equivalent resistance of series and parallel connections of two resistances are given by the formula: (a) R 1 = r 1 + r 2 (Series) (b) R 2 = (r 1 * r 2 ) / (r 1 + r 2 ) (Parallel) Using a switch case statement, write a program to enter the value of r 1 and r 2 . Calculate and display the equivalent resistances accordingly.

Answered By

38 Likes


Related Questions