java - The method println(double) in the type PrintStream is not applicable for the arguments (String, double) -


here code:

import java.util.scanner;  public class movieprices {     public static void main(string[] args) {         scanner user = new scanner(system.in);         double adult = 10.50;         double child = 7.50;         system.out.println("how many adult tickets?");         int fnum = user.nextint();          double aprice = fnum * adult;         system.out.println("the cost of movie tickets before ", aprice);      } } 

i new coding , project of mine school. trying print variable aprice within string getting error in heading.

instead of this:

system.out.println("the cost of movie tickets before ", aprice); 

do this:

system.out.println("the cost of movie tickets before " + aprice); 

this called "concatenation". read this java trail more info.

edit: use formatting via printstream.printf. example:

double aprice = 4.0 / 3.0; system.out.printf("the cost of movie tickets before %f\n", aprice); 

prints:

the cost of movie tickets before 1.333333

you this:

double aprice = 4.0 / 3.0; system.out.printf("the cost of movie tickets before $%.2f\n", aprice); 

this print:

the cost of movie tickets before $1.33

the %.2f can read "format (the %) number (the f) 2 decimal places (the .2)." $ in front of % show, btw, it's not part of format string other saying "put $ here". can find formatting specs in formatter javadocs.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -