pull/485/merge
Safouene-Chemkhi 2 years ago committed by GitHub
commit 1b66e3547c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,39 @@
/**
*
*/
import java.util.*;
import java.lang.Math;
/**
* @author safouene
*
*/
public class bin2dec {
/**
* @param args
*/
public static boolean arrondi(String s) {
boolean b = true;
for (int i = 0; i < s.length(); i++) {
if(s.charAt(i) != '0' && s.charAt(i) != '1') { return false;}
}
return true;
}
public static void main(String[] args) {
System.out.println("Type a binary number");
Scanner sc = new Scanner(System.in);
String binNumber = sc.nextLine();
while (!arrondi( binNumber )) {
System.out.println("Error, type again");
binNumber = sc.nextLine();
}
int decNumber = 0;
int l = binNumber.length();
for (int i = 0; i < l; i++) {
decNumber += Character.getNumericValue(binNumber.charAt(i)) *Math.pow(2, l-i);
}
System.out.print(decNumber);
}
}

@ -0,0 +1,33 @@
import java.util.Scanner;
/**
*
*/
/**
* @author safouene
*
*/
public class dollar2cent {
/**
* @param args
*/
public static void main(String[] args) {
System.out.println("Type number");
Scanner sc = new Scanner(System.in);
float number = sc.nextFloat();
number *= 100;
int cents = (int)number;
int quarter = cents / 25;
cents-= quarter*25;
int dimes = cents / 10;
cents-= dimes*10;
int nickel = cents / 5;
cents-= nickel*5 ;
int pennies = cents / 1;
System.out.println((int)number + "cents : " +quarter + " quarters , " + dimes + " dimes , " + nickel + " nickel and " + pennies + " pennies");
}
}
Loading…
Cancel
Save