Create a public method getTotalCurrent() to compute and display total current in 2 decimal values.
Total current is equal to the ratio of voltage and total resistance. (I = V/R)
import java.util.Scanner;
public class current{
public static void getTotalCurrent(){
Scanner scan= new Scanner(System.in);
double i,v,r;
System.out.println("Enter voltage in volts");
v= scan.nextInt();
System.out.println("enter resistance in ohms");
r= scan.nextInt();
i=v/r;
System.out.printf("%.2f",i);
}
public static void main(String []args) {
getTotalCurrent();
}
}
Comments
Leave a comment