Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.text.DecimalFormat;
- public class Resistencia {
- public static void main(String[] args) {
- int i = 0;
- double[] resistances = new double[3];
- while(i < 3) {
- Scanner sc = new Scanner(System.in);
- System.out.println(String.format("Ingrese resistencia %d:", i+1));
- String resistance = sc.nextLine();
- double resistance_as_long = Double.parseDouble(resistance);
- if (resistance_as_long > 0){
- double processed_resistance = 1/resistance_as_long;
- resistances[i] = processed_resistance;
- i++;
- }
- else {
- System.out.println("------------------------");
- System.out.println("Ingrese un número positivo");
- System.out.println("------------------------");
- continue;
- }
- }
- double resistances_sum = resistances[0] + resistances[1] + resistances[2];
- double total_resistance = 1/resistances_sum;
- System.out.println("------------------------");
- DecimalFormat df = new DecimalFormat("#.##");
- System.out.println("La resistencia total es de " + df.format(total_resistance));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement