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 s=scanner.nextLine();
            String c=s.replaceAll("[a-zA-Z]","");
            double cap=Double.parseDouble(c);
            String t=s.replaceAll("[0-9]","");
//            double cap=Double.parseDouble(s.substring(0,s.length()-2));
            if(cap==0){
                break;
            }
            if(t.equals("B")) {
                System.out.println(0);
            }
            if(t.equals("KB")) {
                System.out.printf("%.0f\n",cap*(Math.pow(2,10)-Math.pow(10,3)));
            }
            if(t.equals("MB")) {
                System.out.printf("%.0f\n",cap*(Math.pow(2,20)-Math.pow(10,6)));
            }
            if(t.equals("GB")) {
                System.out.printf("%.0f\n",cap*(Math.pow(2,30)-Math.pow(10,9)));
            }
            if(t.equals("TB")) {
                System.out.printf("%.0f\n",cap*(Math.pow(2,40)-Math.pow(10,12)));
            }
        }
    }
}

Double click to view unformatted code.


Back to problem 96