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)
Write a program to input the value of r1 and r2. Calculate and display the output of the equivalent resistance as per User's choice.
only a java program. ....
Answers
import java.util.*;
public class Resistances
{
public static void main (String args [])
{
Scanner in = new Scanner (System.in);
int n;
double r1, r2, rs, rp;
System.out.println(" enter 1 for series resistance, enter 2 for parallel resistance");
System.out.println("enter your choice:");
n = in.nextInt();
switch (n)
{
case 1:
System.out.println(" enter the value of r1 and r2:");
r1 = in.nextInt();
r2 = in.nextInt();
rs = r1+r2;
System.out.println("Resistance in series =" +rs);
break;
case 2:
System.out.println(" enter the value of r1 and r2:");
r1 = in.nextInt();
r2 = in.nextInt();
rp = (r1*r2)/(r1+r2);
System.out.println(" Resistance in parallel =" +rp);
break;
default:
System.out.println(" Wrong Choice !!!");
}
}
}
Answer:
//To enter the value of two resistances and display the equivalent resistances
import java.util.*;
public class resistance
{
public static void main()
{
Scanner sc= new Scanner(System.in);
System.out.println("1. Series");
System.out.println("2. Parallel");
System.out.print("Enter your choice(1 or 2): ");
int c=sc.nextInt();
System.out.println("Enter R1");
System.out.println("Enter R2");
int r1=sc.nextInt();
int r2=sc.nextInt();
int R1=0, R2=0;
switch(c)
{
case 1:
R1=r1+r2;
System.out.println(R1);
break;
case 2:
R2=(r1*r2)/(r1+r2);
System.out.println(R2);
break;
default:
System.out.println("Invalid choice");
}
}
}