I'm trying to find the best way to give "args" a input variable, it isn't working like how I want. These are the instructions my professor wants me to follow: write a program that takes two double command line arguments representing the sides of a rectangle The program should then call a void function that reports the area of the rectangle accurate to three decimal places public static void main(String args) { Scanner scan = new Scanner(System.in); System.out.println("Enter length and width of rectangle " + args); args = scan.nextLine(); for (int i=0; i < args.length; i++) { System.out.println(args[i]); } Double area= Double.parseDouble (args[0]) * Double.parseDouble (args[1]); System.out.println(" Area of rectangle is :" + String.format("%.3f", area)); } }
I'm trying to find the best way to give "args" a input variable, it isn't working like how I want.
These are the instructions my professor wants me to follow: write a program that takes two double command line arguments representing the sides of a rectangle
The program should then call a void function that reports the area of the rectangle accurate to three decimal places
public static void main(String args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter length and width of rectangle " + args);
args = scan.nextLine();
for (int i=0; i < args.length; i++)
{
System.out.println(args[i]);
}
Double area= Double.parseDouble (args[0]) * Double.parseDouble (args[1]);
System.out.println(" Area of rectangle is :" + String.format("%.3f", area));
}
}
Step by step
Solved in 2 steps with 2 images