Java Reference
In-Depth Information
public class Ch3_PrExercise2
{
public static void main(String[] args)
{
System.out.print("Enter the height of the cylinder: ");
radius = console.nextDouble();
System.out.println();
3
static Scanner console = new Scanner(System.in);
System.out.println("Volume of the cylinder = "
+ PI * Math.pow(radius, 2.0) * height);
System.out.print("Enter the radius of the base of the "
+ " cylinder: ");
height = console.nextDouble();
System.out.println();
double height;
double radius;
System.out.println("Surface area: "
+ (2 * PI * Math.pow(radius, 2.0))
+ (2 * PI * radius * height));
static final double PI = 3.14159;
}
}
import java.util.*;
3. Write a program that prompts the user to enter the weight of a person in
kilograms and outputs the equivalent weight in pounds. Output both the
weights rounded to two decimal places. (Note that 1 kilogram ΒΌ 2.2
pounds.) Format your output with two decimal places.
4. During each summer John and Jessica grow vegetables in their back yard and
buy seeds and fertilizer from a local nursery. The nursery carries different
types of vegetable fertilizers in various bag sizes. When buying a particular
fertilizer, they want to know the price of the fertilizer per pound and the cost
of fertilizing per square foot. The following program prompts the user to
enter the size of the fertilizer bag, in pounds, the cost of the bag, and the
area, in square feet, that can be covered by the bag. The program should
output the desired result. However, the program contains logic errors. Find
and correct the logic errors so that the program works properly.
//Logic errors.
import java.util.*;
public class Ch3_PrExercise4
Search WWH ::




Custom Search