having a problem with executing this in jGRASP not acceptin user input

class salestax {
 public static void main (String[] args)  {
  try   { 
  double price = Double.valueOf(args[0]).doubleValue();
  double salestax = price * 0.0825;
 System.out.println("Sales tax is " + salestax);
 }
  catch (NumberFormatException e)   {
   System.err.println("Usage: java salestax price" );
	 }
	  catch (ArrayIndexOutOfBoundsException e) {
	   System.err.println("Usage: java salestax price" );
	 }
		  catch (Exception e) { System.err.println(e);
	   }
	 }
	  }

Recommended Answers

All 4 Replies

Ehhh... We knows you have problem, but What is the problem doc ?

Double.valueOf(args[0]).doubleValue()

Extracts a double value from the given String object (args[0]). Same can be achieved a bit more easily by just Double.parseDouble(args[0])

i am unable to enter the price value and the response after running is Usage: java salestax price thanks

i am unable to enter the price value and the response after running is Usage: java salestax price thanks

So, it says Usage: java salestax price So on the console you should type: java salestax <price> Ex: java salestax 10 (where 10 is the price)

Click "Build" / "Run Arguments" in jGRASP to make the arguments entry field visible.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.