-3

I am trying to make an array so that whatever the byte input, the next three answer will multiply itself by 1024. At the moment the inputs are all the same. Grateful if anyone could help

public class ExcerciseFour {
    static Scanner keyboard = new Scanner(System.in);

    public static void main(String[] args) {
    final String [] UNITS = {"B","KB","MB","GB"};

    double bytes;
    double kilobytes;
    double megabytes;
    double gigabytes;

    System.out.print("Enter in bytes: ");
    bytes = keyboard.nextDouble();
    kilobytes = (bytes/1024);
    megabytes = (bytes/1048576);
    gigabytes = (bytes/1073741824);

//  System.out.println(bytes+"bytes"+" is equivalent to "+kilobytes+(UNITS[1])+", "+megabytes+UNITS[2]+", "+gigabytes+UNITS[3]+".");

    double [] conversion = new double [3];
    for(int i=0;i<conversion.length;i++){
            conversion[i]=bytes/1024;
        }
        System.out.println(Arrays.toString(conversion));
    }

}
4

2 回答 2

0

它们都是相同的,因为您将它们全部分配给它们bytes/1024。既然bytes不改变,它们应该都是一样的。

要解决此问题,您可以将辅助变量除以 1024 并重新分配给自身。

于 2013-10-11T09:28:05.403 回答
0

类似的东西

 val = bytes
 for(int i=0;i<conversion.length;i++)
 {
        conversion[i]=val;
        val /= 1024
 } 
于 2013-10-11T09:28:09.593 回答