Computers and Technology, 09.10.2021 14:00 la200564
public class Exercise_07 { public static void main(String[] args) { System. out. println(bin2Dec("1100100")); // Purposely throwing an exception... System. out. println(bin2Dec("lafkja")); } public static int bin2Dec(String binary) throws NumberFormatException { if (!isBinary(binary)) { throw new NumberFormatException(binary + " is not a binary number."); } int power = 0; int decimal = 0; for (int i = binary. length() - 1; i >= 0; i--) { if (binary. charAt(i) == '1') { decimal += Math. pow(2, power); } power++; } return decimal; } public static boolean isBinary(String binary) { for (char ch : binary. toCharArray()) { if (ch != '1' && ch != '0') return false; } return true; } }
Answers: 3
Computers and Technology, 22.06.2019 12:10
1. declare a constant named cents_per_pound and initialize with 25. 2. get the shipping weight from user input storing the weight into shipweightpounds. 3. using flat_fee_cents and cents_per_pound constants, assign shipcostcents with the cost of shipping a package weighing shipweightpounds.
Answers: 2
Computers and Technology, 23.06.2019 09:00
What provides an array of buttons for quick access to commonly used commands and tools
Answers: 1
Computers and Technology, 23.06.2019 19:30
You can apply several different worksheet themes from which tab?
Answers: 1
Computers and Technology, 23.06.2019 20:30
If chris has a car liability insurance, what damage would he be covered for
Answers: 1
public class Exercise_07 { public static void main(String[] args) { System. out. println(bin2Dec("11...
Mathematics, 13.10.2019 22:30
Chemistry, 13.10.2019 22:30
Biology, 13.10.2019 22:30
English, 13.10.2019 22:30
World Languages, 13.10.2019 22:30
Social Studies, 13.10.2019 22:30
History, 13.10.2019 22:30
Mathematics, 13.10.2019 22:30
History, 13.10.2019 22:30