Advertisement
ADL_Rodrigo_Silva

Untitled

Dec 13th, 2021
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.08 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.text.DecimalFormat;
  3.  
  4. public class Resistencia {
  5.     public static void main(String[] args) {
  6.         int i = 0;
  7.         double[] resistances = new double[3];
  8.        
  9.         while(i < 3) {
  10.             Scanner sc = new Scanner(System.in);
  11.             System.out.println(String.format("Ingrese resistencia %d:", i+1));
  12.            
  13.             String resistance = sc.nextLine();
  14.             double resistance_as_long = Double.parseDouble(resistance);
  15.            
  16.             if (resistance_as_long > 0){
  17.                 double processed_resistance = 1/resistance_as_long;
  18.                 resistances[i] = processed_resistance;
  19.                 i++;
  20.             }
  21.             else {
  22.                 System.out.println("------------------------");
  23.                 System.out.println("Ingrese un número positivo");
  24.                 System.out.println("------------------------");
  25.                 continue;
  26.             }
  27.         }
  28.        
  29.         double resistances_sum = resistances[0] + resistances[1] + resistances[2];
  30.         double total_resistance = 1/resistances_sum;
  31.        
  32.         System.out.println("------------------------");
  33.         DecimalFormat df = new DecimalFormat("#.##");
  34.         System.out.println("La resistencia total es de " + df.format(total_resistance));
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement