Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- public class Calculatrice {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- System.out.println("\t\t\t*** Welcome ***");
- int a = Integer.parseInt(args[0]);
- int b = Integer.parseInt(args[1]);
- String c = args[2];
- float d = Float.parseFloat(args[3]);
- int [] e = fTransform(args[4]);
- // a at the power of b :
- System.out.print(a + " at the power of " + b + " = ");
- System.out.println(fPow(a,b));
- // Factorial of a :
- System.out.print("Factorial of " + a + " = ");
- System.out.println(fFact(a));
- // Arrangement of a and b :
- System.out.print("Arrangement of " + a + " and " + b + " = ");
- System.out.println(fArr(a,b));
- // Combination of a and b :
- System.out.print("Combination of " + a + " and "+ b + " = ");
- System.out.println(fComb(a,b));
- //Conversion to decimal :
- System.out.print("Conversion of " + c + " to decimal = ");
- System.out.println(fConvDec(c));
- //Conversion to hexadecimal :
- System.out.print("Conversion of " + c + " to hexadecimal = ");
- System.out.println(fConvHex(c));
- //Square root of a number :
- System.out.print("Square root of " + d + " = ");
- System.out.println(fSqrt(d));
- //Array before bubble sort :
- System.out.println("Array before bubble sort : ");
- fShow(e);
- //Array after bubble sort :
- System.out.println("Array after bubble sort : ");
- fOrd(e);
- fShow(e);
- }
- public static double fPow(float a,float b) {
- if (b == 0) {
- return 1;
- }
- else {
- return a * Math.pow(a,b-1);
- }
- }
- public static float fArr(float a, float b) {
- if (a > b && a > 0 && b > 0) {
- return fFact(a)/fFact(a-b);
- }
- else {
- return 0.0f;
- }
- }
- public static float fFact(float n) {
- if (n == 1) {
- return 1.0f;
- }
- else {
- return n * fFact(n-1);
- }
- }
- public static float fComb(float a, float b) {
- if (a > b && a > 0 && b > 0) {
- return fArr(a,b) * (1/fFact(b));
- }
- else {
- return 0.0f;
- }
- }
- public static int fConvDec(String n) {
- return Integer.parseInt(n,2);
- }
- public static String fConvHex(String n) {
- return Integer.toString(fConvDec(n),16);
- }
- public static double fSqrt(float a) {
- return fPow(a,0.5f);
- }
- public static void fOrd(int[] n) { // Bubble sort by the way xD
- Arrays.sort(n);
- }
- public static void fShow(int[] t) {
- for(int i = 0; i < t.length; i++) {
- System.out.println("t["+i+"] = "+t[i]);
- }
- }
- public static int[] fTransform(String ch) {
- // TODO :: Re check this part ! ::
- int [] fin = {0,0,0,0,0};
- for(int i = 0; i < ch.length(); i++) {
- char c = ch.charAt(i);
- fin[i] = Character.getNumericValue(c);
- }
- //fin[i++] = Character.getNumericValue(ch.charAt(i));
- return fin;
- }
- /*public static int fRech(int[] tab, int c) {
- int p = 0;
- for(int i = 0; i < tab.length; i++) {
- if (tab[i] == c) {
- p = i;
- }
- }
- return p;
- }
- public static int fMax(int[] tab) {
- int p = tab[0]; int l = tab.length;
- for(int i = 0; i < l;i++) {
- if (tab[i] > p) {
- p = tab[i];
- }
- }
- return p;
- }
- public static int fMin(int[] tab) {
- int p = tab[0]; int l = tab.length;
- for(int i = 0; i < l;i++) {
- if (tab[i] < p) {
- p = tab[i];
- }
- }
- return p;
- }
- public static void fSwap(int a, int b) {
- int tmp = 0;
- tmp = a;
- a = b;
- b = tmp;
- }
- public static int fMaxRange(int[] tab, int pos1, int pos2) {
- int m = tab[0];
- for(int i = pos1; i < pos2; i++) {
- if (tab[i] > m) {
- m = tab[i];
- }
- }
- return m;
- }
- public static int fMinRange(int[] tab, int pos1, int pos2) {
- int m = tab[0];
- for(int i = pos1; i < pos2; i++) {
- if (tab[i] < m) {
- m = tab[i];
- }
- }
- return m;
- }*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement