Advertisement
peterzig

[JAVA] Substancja

Mar 3rd, 2017
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.26 KB | None | 0 0
  1. package substancja;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Substancja {
  6.  
  7.     public static void main(String[] args) {
  8.        
  9.         double max, buff, procent,ilosc;
  10.         int dzien=1;
  11.         Scanner Wejscie = new Scanner(System.in);
  12.        
  13.         while(true)
  14.        {
  15.         System.out.println("Ilosc substancji:");
  16.         ilosc = Wejscie.nextDouble();
  17.         System.out.println("ubytek w %:");
  18.         procent = Wejscie.nextDouble();
  19.         System.out.println("do jakiej ilosci");
  20.         max = Wejscie.nextDouble();
  21.         procent = procent/100;
  22.         System.out.println("procent="+procent);
  23.        
  24.         if(ilosc < 5  || procent > 100 || procent < 0)
  25.             {
  26.             System.out.println("Blad!");
  27.             System.out.print("\nCzy chcesz ponownie uruchomić program? (t/n)? ");
  28.             String var = Wejscie.next();
  29.             if(var.equalsIgnoreCase("T")){// Pasuje zarówno "T" jak i "t"
  30.                 main(null); // jeżeli input to "T" lub "t" wraca do maina
  31.             }
  32.             else if(var.equalsIgnoreCase("N")){
  33.                System.exit(0);
  34.             }
  35.             else {
  36.                 System.exit(0);
  37.             }
  38.           }
  39.        
  40.         buff=ilosc;
  41.         System.out.println("|-----------------------------|");
  42.         System.out.println("| dzień|    gram   |  procent |");
  43.         System.out.println("|-----------------------------|");
  44.         do  
  45.         {
  46.             System.out.printf("|   %d  |    %5.2fg |   %5.1f  | \n",dzien,ilosc,(ilosc/buff)*100 );
  47.             dzien++;
  48.             ilosc = ilosc * procent;
  49.         }
  50.         while(ilosc>max);
  51.         System.out.println("|-----------------------------|");
  52.         System.out.println("Substancja spadla ponizej "+max+"g po "+dzien+" dniach");    
  53.        
  54.          System.out.print("\nCzy chcesz ponownie uruchomić program? (t/n)? ");
  55.             String var = Wejscie.next();
  56.             if(var.equalsIgnoreCase("T")){// Pasuje zarówno "T" jak i "t"
  57.                 main(null); // jeżeli input to "T" lub "t" wraca do maina
  58.             }
  59.             else if(var.equalsIgnoreCase("N")){
  60.                System.exit(0);
  61.             }
  62.             else {
  63.                 System.exit(0);
  64.             }
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement