java - How to add a double with a variable only using one double -
public static void main(string[] args) { scanner in = new scanner(system.in); system.out.println("insert value year (ez = 2014): "); double year = in.nextdouble(); system.out.println("insert value day (ex = 12): "); double day = in.nextdouble(); system.out.println("insert number month (ex = 3): "); double month = in.nextdouble(); double totaldays = day; if (month == 1) { } else if (month == 2) { double totaldays = (totalday + 31); } }
i'm trying take totaldays
double , use in if statement. want add variable without using anymore doubles. how?
your code incorrectly re-declares totaldays inside conditional. re-declaring variables in inner scope not want do, though. should use same variable. use compound add-assign operator, this:
totaldays += 31;
Comments
Post a Comment