Advertisement
Ronaldoztupang

Jawaban Rias si Fisikawati 1

Oct 23rd, 2019
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.57 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. public class Solution {
  5.  
  6.  
  7.  
  8.     public static void main(String[] args) {
  9.     String s1,s2,s3,s4; int x = 0;
  10.     Scanner masuk = new Scanner(System.in);
  11.     s1 = masuk.nextLine();
  12.     s2 = masuk.nextLine();
  13.         s3 = masuk.nextLine();
  14.         s4 = masuk.nextLine();
  15.         if(s1.equals("cari"))
  16.         {
  17.             x++; s1 = "0";
  18.         }  
  19.         if(s2.equals("cari"))
  20.         {
  21.             x++; s2 = "0";
  22.         }
  23.         if(s3.equals("cari"))
  24.         {
  25.             x++; s3 = "0";
  26.         }
  27.         if(s4.equals("cari"))
  28.         {
  29.             x++; s4 = "0";
  30.         }
  31.         double v1 = Double.valueOf(s1);
  32.         double r1 = Double.valueOf(s2);
  33.         double v2 = Double.valueOf(s3);
  34.         double r2 = Double.valueOf(s4);
  35.         if(x>=2)
  36.         {
  37.             System.out.print("INFINITY");
  38.         }
  39.         else if(x==1)
  40.         {
  41.             if(v1==0)
  42.             {
  43.                 v1 = v2*r1/r2;
  44.                 System.out.printf("v1 = %.2f",v1);
  45.             }
  46.             else if(r1==0)
  47.             {
  48.                 r1 = v1*r2/v2;
  49.                 System.out.printf("r1 = %.2f",r1);
  50.             }
  51.             else if(v2==0)
  52.             {
  53.                 v2 = v1*r2/r1;
  54.                 System.out.printf("v2 = %.2f",v2);
  55.             }
  56.             else if(r2==0)
  57.             {
  58.                 r2 = v2*r1/v1;
  59.                 System.out.printf("r2 = %.2f",r2);
  60.             }
  61.         }
  62.         else if(x==0)
  63.         {
  64.             System.out.print("APA YANG DICARI?");
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement