Question: Heres a peek ahead. In this chapter, you learned about integers and the type int. Java can also represent floating-point numbers that contain decimal points,
Here’s a peek ahead. In this chapter, you learned about integers and the type int. Java can also represent floating-point numbers that contain decimal points, such as 3.14159. Write an application that inputs from the user the radius of a circle as an integer and prints the circle’s diameter, circumference and area using the floating-point value 3.14159 for π. Use the techniques shown in Fig. 2.7. Use the following formulas (r is the radius): diameter = 2r circumference = 2πr area = πr2 Do not store the results of each calculation in a variable. Rather, specify each calculation as the value that will be output in a System.out.printf statement. The values produced by the circumference and area calculations are floating-point numbers. Such values can be output with the format specifier %f in a System.out.printf statement. You’ll learn more about floating-point numbers.
Fig. 2.7

I // Fig. 2.7: Addition.java 2 // Addition program that inputs two numbers then displays their sum. 3 import java.util. Scanner; // program uses class Scanner 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 21 public class Addition { // main method begins execution of Java application public static void main(String[] args) { // create a Scanner to obtain input from the command window Scanner input = new Scanner (System.in); System.out.print("Enter first integer: "); // prompt int number1 = input.nextInt(); // read first number from user System.out.print("Enter second integer : "); // prompt int number2 = input.nextInt(); // read second number from user int sum = number1 + number2; // add numbers, then store total in sum System.out.printf ("Sum is %d%n", sum); // display sum } // end method main } // end class Addition
Step by Step Solution
3.43 Rating (153 Votes )
There are 3 Steps involved in it
To solve the problem described in your question we can create a Java program that will follow similar steps to the program in the figure provided Fig ... View full answer
Get step-by-step solutions from verified subject matter experts
