Array in Java beginner -
i'm beginner in coding. write project convert degree f c , c f using command line argument. here got far:
public class implementation { public static void main(string[] args) { { string[] days = {"very cold", "cold", "mild", "very mild", "warm", "very warm", "hot"}; } } if (args.length != 3) { system.out.println("error! please try again."); system.exit(0); } else { double degree; string celsius; string fahrenheit; degree = double.parsedouble(args[0]); celsius = args[1]; fahrenheit = args[2]; switch (celsius) { case "c": system.out.printf("%n%s celsius %s fahrenheit\n", args[0], ( 5.0 / 9.0 * (degree - 32))); break; case "f": system.out.printf("%n%s fahrenheit %s celsius\n", args[0], ( 9.0 / 5.0 * (degree + 32))); break; } } } }
we have range degree:
below 0 degrees = cold
from 0 32 = cold
from 33 50 = mild
from 51 60 = mild
from 61 70 = warm
from 71 90 = warm
above 90 = hot
i have question array. how show array in output depend on specific degree? please , thank much!
you defined days in own scope, that's why it's not accessible:
{ string[] days = {"very cold", "cold", "mild", "very mild", "warm", "very warm", "hot"}; }
simply remove curly braces around it.
string[] days = {"very cold", "cold", "mild", "very mild", "warm", "very warm", "hot"};
Comments
Post a Comment