View Code of Problem 96

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while(scanner.hasNext()) {
			String string = scanner.next();
			double n = Double.parseDouble(string.replaceAll("[a-zA-Z]", ""));
			String s = string.replaceAll("[0-9]", "");
			if(n == 0) {
				break;
			}
			else {
				if(s.equals("B")) {
					System.out.println(0);
				}
				else if(s.equals("KB")) {
					System.out.printf("%.0f\n",n * (Math.pow(2, 10)- Math.pow(10, 3)));
				}
				else if(s.equals("MB")) {
					System.out.printf("%.0f\n",n * (Math.pow(2, 20)- Math.pow(10, 6)));
				}
				else if (s.equals("GB")) {
					System.out.printf("%.0f\n",n * (Math.pow(2, 30)- Math.pow(10, 9)));
				}
				else if (s.equals("TB")) {
					System.out.printf("%.0f\n",n * (Math.pow(2, 40)- Math.pow(10, 12)));
				}
				
			}
		}
	}
}

Double click to view unformatted code.


Back to problem 96