gpt4 book ai didi

java - 如何用数组进行减法/除法

转载 作者:行者123 更新时间:2023-12-01 23:25:25 27 4
gpt4 key购买 nike

//Declare and intialize variables - programmer to provide initial values
Scanner in = new Scanner(System.in);
String city = "Daytona Beach";
String state = "Florida";
double a =0;

String month [] ={"Jan", "Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
double temperature [] = {58.4, 60.0, 64.7, 68.9,74.8, 79.7, 81.7, 81.5,79.9,74.0,67.0,60.8};
double precipitation [] ={3.1, 2.7,3.8,2.5,3.3,5.7,5.2,6.1,6.6,4.5,3.0,2.7};
String tempLabel = "F"; //initialize to F
String precipLabel = "inch"; //initialize to inch

double c [] = {32.0};
double q [] = {0.5555};

//INPUT - ask user for temp and preciptation scale choice
System.out.print("Choose the temperature scale (F = Fahrenheit, C = Celsius): ");
String tempChoice = in.next();
System.out.print("Choose the precipitation scale (i = inches, c = centimeteres): ");
String precipChoice = in.next();


//PROCESSING - convert from F to C and in to cm based on user's choices

// remember 5/9 = 0, 5.0/9 = .5555

if(tempChoice.equalsIgnoreCase("C"))
{
tempLabel="(C)";


for( int index = 0; index < temperature.length; index++)
{

}

}

//Convert in values to cm; replace the current values in precipitation
if(precipChoice.equalsIgnoreCase("c"))
{
precipLabel="(cm)";


}

//OUTPUT - print table using printf to format and align data

System.out.println();
System.out.println("Climate Data");
System.out.println("Location: " + city +", " + state);
System.out.printf("%5s %18s %s %18s %s","Month","Temperature",tempLabel,"Precipitation",precipLabel);
System.out.printf("***************************************************");
System.out.printf("%s\n",month);
System.out.println();
System.out.printf("***************************************************");
System.out.println();

不用担心降水量的转换。如何转换多个数组值(以华氏度为单位)?我尝试这样做(例如):a[i] = b[i]-c[i],但总是出现关闭温度数组的错误。错误是“预期的‘]’。

** 我还收到编译器警告“上次编译的警告:

  • 非可变参数调用最后一个参数类型不精确的可变参数周长;

  • 转换为 java.lang.Object 以进行可变参数调用

  • 强制转换为 java.lang.Object[] 以进行非可变参数调用并抑制警告

最佳答案

如果您在示例中引用的 a 是您声明的 double a,那么这是因为 a 不是数组。

此外,c 和 q 很可能是普通的 double 而不是数组

关于java - 如何用数组进行减法/除法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20083831/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com