Java Reference
In-Depth Information
System.out.println();
System.out.printf("Area of the rectangle = %.2f%n",
(length * width));
System.out.printf("Surface area of the cylinder: %.2f%n",
(2 * PI * radius * height
+ 2 * PI * Math.pow(radius, 2.0)));
}
else
System.out.println("The program does not handle "
+ shape);
4
}
static Scanner console = new Scanner(System.in);
static final double PI = 3.1416;
}
import java.util.*;
5. Write a program to implement the algorithm you designed in Exercise 17 of
Chapter 1.
6. In a right triangle, the square of the length of one side is equal to the sum of
the squares of the lengths of the other two sides. Write a program that
prompts the user to enter the lengths of three sides of a triangle and then
outputs a message indicating whether the triangle is a right triangle.
7. A box of cookies can hold 24 cookies and a container can hold 75 boxes
of cookies. Write a program that prompts the user to enter the total
number of cookies. The program then outputs the number of boxes and
the number of containers to ship the cookies. Note that each box must
contain the specified number of cookies and each container must contain
the specified number of boxes. If the last box of cookies contains less
than the number of specified cookies, you can discard it, and output
the number of leftover cookies. Similarly, if the last container contains
less than the number of specified boxes, you can discard it, and output
the number of leftover boxes.
8. The roots of the quadratic equation ax 2 +bx+c ¼ 0,a 0 are given by the
following formula:
b
p
b 2 4 ac
2 a
In this formula, the term b 2 4ac is called the discriminant.Ifb 2 4ac ¼ 0,
then the equation has a single (repeated) root. If b 2 4ac > 0, the equation
has two real roots. If b 2 4ac < 0, the equation has two complex roots.
Write a program that prompts the user to input the value of a (the
coefficient of x 2 ), b (the coefficient of x), and c (the constant term), and
outputs the type of roots of the equation. Furthermore, if b 2 4ac 0, the
Search WWH ::




Custom Search