java - Integer / Double value -
i trying write code says whether cheapskate, patron, etc depending on amount donate.
this code:
public class donor { public static void main(string [] args) { system.out.println(" % java donor"); system.out.print("enter amount of contribution: $"); java.util.scanner sc = new java.util.scanner(system.in); double money = sc.nextint(); if ( money >= 0) { if ( money < 15 ) { system.out.println("cheapskate!"); } if ( money >= 15 && money < 200) { system.out.print("friend!"); } if ( money >= 200 && money < 1000) { system.out.println("supporter!"); } if ( money >= 1000 && money < 10000) { system.out.println("patron!"); } if (money >= 10000) { system.out.println("benefactor!"); } } else { system.out.println("you have entered invalid value!"); } } }
the problem accepts integers. if enter 90.34 won't accept , fail. how can fix issue?
thanks
you have defined input variable money double reading int scanner here:
double money = sc.nextint();
use scanner nextdouble read double input instead of int.
double money = sc.nextdouble();
Comments
Post a Comment