Temperature Computation in Java?

时间:2016-02-12 21:06:38

标签: java loops temperature

Basically, the task is to compute the temperature of a warm object after it has been put in a freezer. The freezer temperature is constant at -20 degrees. Once the object is in the freezer, its temperature drops by (K * dt) degrees in each second, where K=0.001 and dt is the difference between the current object temperature and the freezer temperature. This method should be able compute the temperature of the object (with given initial temperature) after it has been in the freezer for a certain number of seconds.

The solution should feature a loop that computes the changing temperature of the object second-by-second. In each second, the temperature should drop by (K * dt) where dt is the difference between the current object temperature (as it is at the start of that second) and the freezer temperature. here is my code:

android {
  packagingOptions {
    pickFirst 'META-INF/LICENSE.txt' // picks the JavaMail license file
  }
}
repositories { 
  jcenter()
  maven {
    url "https://maven.java.net/content/groups/public/"
  }
} 
dependencies {
  compile 'com.sun.mail:android-mail:1.5.5'
  compile 'com.sun.mail:android-activation:1.5.5'
}

My problem is that I don't know how to implement it in a loop. Any help would be appreciated :). Thank you :).

3 个答案:

答案 0 :(得分:1)

This method would do it. I added the print statement so you can see the progression, but you'll want to remove it.

`tableCols<- 'Sessions, Pages/session, Session duration, Bounce rate, No. or return visits, Age, 18-24, 25-34, 35-44, 45-54, 55-64, 65+, % Male, Device, Mobile, Desktop, Tablet, Affinity category, Movie Lover, TV Lover, Technophile, In-Market segment, Employment, Education Autos & Vehicles  '
tableCols<-strsplit(as.character(tableCols), ',' )
    Table<-data.frame(Dimension =unlist(tableCols), All_users = numeric(24),    Non_bounce = numeric(24))
    #this works and is in the first row
    Table$All_users[Table$Dimension=="Sessions"]<-sum(gaDatCY15$sessions)
    #this does not
    Table$All_users[Table$Dimension=="Session duration"]<-sum(gaDatCY15a$sessionDuration)`

Test

public static double temperature(double initialTemperature, int seconds) {
    double currentTemp = initialTemperature;
    for (int time = 1; time <= seconds; time++) {
        currentTemp -= K * (currentTemp - FREEZER_TEMPERATURE);
        System.out.printf("After %d seconds, temperature is %f%n", time, currentTemp);
    }
    return currentTemp;
}

Output

System.out.println(temperature(70, 60));

答案 1 :(得分:1)

preventDefault

答案 2 :(得分:0)

$scope.TypeFileter = ['AA', 'BB', 'CC', 'DD', 'EE', /*... so on */]