Advertisement
DroidZed

java prog

Jan 21st, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.77 KB | None | 0 0
  1. import java.util.Arrays;
  2. public class Calculatrice {
  3.  
  4.     public static void main(String[] args) {
  5.         // TODO Auto-generated method stub
  6.         System.out.println("\t\t\t*** Welcome ***");
  7.         int a = Integer.parseInt(args[0]);
  8.         int b = Integer.parseInt(args[1]);
  9.         String c = args[2];
  10.         float d = Float.parseFloat(args[3]);
  11.         int [] e = fTransform(args[4]);
  12.         // a at the power of b :
  13.         System.out.print(a + " at the power of " + b + " = ");
  14.         System.out.println(fPow(a,b));
  15.         // Factorial of a :
  16.         System.out.print("Factorial of " + a + " = ");
  17.         System.out.println(fFact(a));
  18.         // Arrangement of a and b :
  19.         System.out.print("Arrangement of " + a + " and " + b + " = ");
  20.         System.out.println(fArr(a,b));
  21.         // Combination of a and b :
  22.         System.out.print("Combination of " + a + " and "+ b + " = ");
  23.         System.out.println(fComb(a,b));
  24.         //Conversion to decimal :
  25.         System.out.print("Conversion of " + c + " to decimal = ");
  26.         System.out.println(fConvDec(c));
  27.         //Conversion to hexadecimal :
  28.         System.out.print("Conversion of " + c + " to hexadecimal = ");
  29.         System.out.println(fConvHex(c));
  30.         //Square root of a number :
  31.         System.out.print("Square root of " + d + " = ");
  32.         System.out.println(fSqrt(d));
  33.         //Array before bubble sort :
  34.         System.out.println("Array before bubble sort : ");
  35.         fShow(e);
  36.         //Array after bubble sort :
  37.         System.out.println("Array after bubble sort : ");
  38.         fOrd(e);
  39.         fShow(e);
  40.     }
  41.     public static double fPow(float a,float b) {
  42.         if (b == 0) {
  43.             return 1;
  44.         }
  45.         else {
  46.             return a * Math.pow(a,b-1);
  47.         }
  48.     }
  49.     public static float fArr(float a, float b) {
  50.         if (a > b && a > 0 && b > 0) {
  51.             return fFact(a)/fFact(a-b);
  52.         }
  53.         else {
  54.             return 0.0f;
  55.         }
  56.     }
  57.     public static float fFact(float n) {
  58.         if (n == 1) {
  59.             return 1.0f;
  60.         }
  61.         else {
  62.             return n * fFact(n-1);
  63.         }
  64.     }
  65.     public static float fComb(float a, float b) {
  66.         if (a > b && a > 0 && b > 0) {
  67.             return fArr(a,b) * (1/fFact(b));
  68.         }
  69.         else {
  70.             return 0.0f;
  71.         }
  72.     }
  73.     public static int fConvDec(String n) {
  74.         return Integer.parseInt(n,2);
  75.     }
  76.     public static String fConvHex(String n) {
  77.         return Integer.toString(fConvDec(n),16);
  78.     }
  79.     public static double fSqrt(float a) {
  80.         return fPow(a,0.5f);
  81.     }
  82.     public static void fOrd(int[] n) { // Bubble sort by the way xD
  83.         Arrays.sort(n);
  84.     }
  85.     public static void fShow(int[] t) {
  86.         for(int i = 0; i < t.length; i++) {
  87.             System.out.println("t["+i+"] = "+t[i]);
  88.         }
  89.     }
  90.     public static int[] fTransform(String ch) {
  91.         // TODO :: Re check this part ! ::
  92.         int [] fin = {0,0,0,0,0};
  93.         for(int i = 0; i < ch.length(); i++) {
  94.             char c = ch.charAt(i);
  95.             fin[i] = Character.getNumericValue(c);
  96.         }
  97.         //fin[i++] = Character.getNumericValue(ch.charAt(i));
  98.         return fin;
  99.     }
  100.     /*public static int fRech(int[] tab, int c) {
  101.         int p = 0;
  102.         for(int i = 0; i < tab.length; i++) {
  103.             if (tab[i] == c) {
  104.                 p = i;
  105.             }
  106.         }
  107.         return p;
  108.     }
  109.     public static int fMax(int[] tab) {
  110.         int p = tab[0]; int l = tab.length;
  111.         for(int i = 0; i < l;i++) {
  112.             if (tab[i] > p) {
  113.                 p = tab[i];
  114.             }
  115.         }
  116.         return p;
  117.     }
  118.     public static int fMin(int[] tab) {
  119.         int p = tab[0]; int l = tab.length;
  120.         for(int i = 0; i < l;i++) {
  121.             if (tab[i] < p) {
  122.                 p = tab[i];
  123.             }
  124.         }
  125.         return p;
  126.     }
  127.         public static void fSwap(int a, int b) {
  128.         int tmp = 0;
  129.         tmp = a;
  130.         a = b;
  131.         b = tmp;
  132.     }
  133.         public static int fMaxRange(int[] tab, int pos1, int pos2) {
  134.         int m = tab[0];
  135.         for(int i = pos1; i < pos2; i++) {
  136.             if (tab[i] > m) {
  137.                 m = tab[i];
  138.                 }
  139.             }
  140.         return m;
  141.     }
  142.     public static int fMinRange(int[] tab, int pos1, int pos2) {
  143.         int m = tab[0];
  144.         for(int i = pos1; i < pos2; i++) {
  145.             if (tab[i] < m) {
  146.                 m = tab[i];
  147.                 }
  148.             }
  149.         return m;
  150.     }*/
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement