Computer Science, asked by Anonymous, 7 months ago

The equivalent resistance of series and parallel connections of two resistances is 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 resistance accordingly.

Answers

Answered by DüllStâr
120

Required Program:

import java, util.*;

public class Resistances

{

public static void main(String args[])

{

Scanner.sc= new Scanner(System.in);

int ch;

double r1,r2,rs,rp;

System.out.println("Enter 1 for Series Resistance"); System.out.println("Enter 2 for Parallel Resistance");

System.out.print("Enter your choice: ");

ch=sc.nextInt();

switch(ch)

{

case 1:

System.out.print("Enter the value of r1 and r2: ");

r1=sc.nextInt();

r2=sc.nextint();

rs=r1+r2;

System.out.print("Resistance in series is: "+rs);

break;

case 2:

System.out.print("Enter the value of r1 and r2:");

r1=sc.nextint():

r2=sc.nextInt();

rp=(r1*r2)/(r1+r2);

System.out.print("Resistance in parallel is: "+rp);

break;

default:

System.out.print("Invalid Choice");

}

}

}

_____________________________

Input:

Enter your choice:

 \blue{1}

Enter value of r1 and r2

 \blue{21}

 \blue{45}

_____________________________

Output:

Enter 1 for Series Resistance

Enter 2 for Series Resistance

Enter your choice:1

Enter value of r1 and r2:

21

45

Resistance in series is: 66

_____________________________

Details about program:

  • As requested switch case is used✓
  • program is written using Java language
  • Scanner class is used

_____________________________

Additional information:

What will happen if break statement is not used ?

If break statement is not used then flow of control will go out side the loop which will result in fall through due to which program will not able to execute

What are variables?

We can say variables are like containers which are used to store values.

Types of variables:

  • Non-static fields

  • Static fields

  • Local variables

  • Parameters

What are datatype?

Datatype is an atribute which tells what type of value should be stored in a variable.

_____________________________

hope it helps!

Answered by ramsadhu2019
10

Answer:

Required Program:

import java, util.*;

public class Resistances

{

public static void main(String args[])

{

Scanner.sc= new Scanner(System.in);

int ch;

double r1,r2,rs,rp;

System.out.println("Enter 1 for Series Resistance"); System.out.println("Enter 2 for Parallel Resistance");

System.out.print("Enter your choice: ");

ch=sc.nextInt();

switch(ch)

{

case 1:

System.out.print("Enter the value of r1 and r2: ");

r1=sc.nextInt();

r2=sc.nextint();

rs=r1+r2;

System.out.print("Resistance in series is: "+rs);

break;

case 2:

System.out.print("Enter the value of r1 and r2:");

r1=sc.nextint():

r2=sc.nextInt();

rp=(r1*r2)/(r1+r2);

System.out.print("Resistance in parallel is: "+rp);

break;

default:

System.out.print("Invalid Choice");

}

}

}

_____________________________

Input:

Enter your choice:

\blue{1}1

Enter value of r1 and r2

\blue{21}21

\blue{45}45

_____________________________

Output:

Enter 1 for Series Resistance

Enter 2 for Series Resistance

Enter your choice:1

Enter value of r1 and r2:

21

45

Resistance in series is: 66

_____________________________

Details about program:

As requested switch case is used✓

program is written using Java language

Scanner class is used

_____________________________

Additional information:

What will happen if break statement is not used ?

If break statement is not used then flow of control will go out side the loop which will result in fall through due to which program will not able to execute

What are variables?

We can say variables are like containers which are used to store values.

Types of variables:

Non-static fields

Static fields

Local variables

Parameters

What are datatype?

Datatype is an atribute which tells what type of value should be stored in a variable.

_____________________________

this is ur answer.......

Similar questions