Advertisement
electricmaster

TemperatureByCricket.java

Sep 22nd, 2016
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.68 KB | None | 0 0
  1. package edu.oakland.production.homework;
  2. import java.util.*;
  3.  
  4. public class TemperatureByCricket{
  5.   public static float getTemp(float chirps){
  6.     float temp;
  7.     temp = chirps/4;
  8.     temp += 40;
  9.     return temp;
  10.   }
  11.  
  12.   public static void main(String[] args){
  13.     Scanner s = new Scanner(System.in);
  14.     float chirps;
  15.     while(true){
  16.       System.out.print("Please enter the number of chirps per minute, or -1 to quit. ");
  17.       chirps = s.nextFloat();
  18.       if(chirps == -1)
  19.         break;
  20.       else if(chirps < 0)
  21.         System.out.println("Error: negative chirps");
  22.       else
  23.         System.out.println("The temperature is " + getTemp(chirps) + "F.");
  24.     }
  25.   }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement