Java Reference
In-Depth Information
System.out.printf("Area = %.2f%n", rectangle(radius));
break ;
case 2:
System.out.print("Enter the length and the width "
+ "of the rectangle: ");
length = console.nextDouble();
width = console.nextDouble();
System.out.println();
System.out.printf("Volume = %.2f%n",
cylinder(radius, height));
break ;
default :
System.out.println("Invalid choice!");
}
switch (choice)
}
System.out.println("To run the program enter: ");
System.out.println("2: To find the area of a circle.");
System.out.println("1: To find the area of rectangle.");
System.out.println("3: To find the volume of a cylinder.");
System.out.println("-1: To terminate the program.");
choice = console.nextInt();
System.out.println();
7
}
public static double rectangle( double l, double w)
{
return l * r;
}
public static double circle( double r)
{
return Math.PI * r * w;
}
public static double cylinder( double bR, double h)
{
return Math.PI * bR * bR * l;
}
}
6. Write a method, reverseDigit , that takes an integer as a parameter and
returns the number with its digits reversed. For example, the value of
reverseDigit(12345) is 54321 . Also, write a program to test your method.
Search WWH ::




Custom Search