Computer Science, asked by jutenwistahn, 10 hours ago

The equivalent resistance of a series and a parallel connection of two resistances are given by the formula:
R1 = r1 + r2
R2 = r1.r2 r1+r2
Write a Java program to input the value of r1 and r2. Calculate and display the output of the equivalent resistance ( R1 and R2).

@Anindhyaadhikari
please answer this question of mine​

Answers

Answered by anindyaadhikari13
1

Solution:

The given problem is solved in Java.

import java.util.Scanner;

public class Main{

   public static void main(String args[]){

       Scanner sc=new Scanner(System.in);

       double r1,r2,e;

       System.out.print("Enter r1: ");

       r1=sc.nextDouble();

       System.out.print("Enter r2: ");

       r2=sc.nextDouble();

       sc.close();

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

       System.out.println("Equivalent resistance: "+e+" ohm.");

   }

}

Explanation:

  • Line 1: Import Scanner class for taking input.
  • Line 2: Class declaration.
  • Line 3: Declaration of main method.
  • Line 4: Object of Scanner class is created for taking input.
  • Line 5: 3 variables are declared which will be used later.
  • Line 6-9: The resistances are taken as input.
  • Line 10: Scanner is closed since input task is over.
  • Line 11: The equivalent resistance is calculated using the formula mentioned.
  • Line 12: The equivalent resistance is displayed on the screen.
  • Line 13:  End of main() method.
  • Line 14: End of class.

See attachment for output.

Attachments:
Similar questions