Question: in java 2 . 2 8 ( Diameter , Circumference and Area of a Circle ) Here s a peek ahead. In this chapter, you
in java
Diameter Circumference and Area of a Circle Heres a peek ahead. In this chapter, you learned about integers and the type int. Java can also represent floatingpoint numbers that contain decimal points, such as Write an application that inputs from the user the radius of a circle as an integer and prints the circles diameter, circumference and area using the floatingpoint value for pi Use the techniques shown in Fig. Note: You may also use the predefined constant Math.PI for the value of pi This constant is more precise than the value Class Math is defined in package java.lang. Classes in that package are imported automatically, so you do not need to import class Math to use it Use the following formulas r is the radius:java
diameter
circumference
area
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 floatingpoint numbers. Such values can be output with the format specifier f in a System.out.printf statement. Youll learn more about floatingpoint numbers in Chapter
Integer Value of a Character Heres another peek ahead. In this chapter, you learned about integers and the type int. Java can also represent uppercase letters, lowercase letters and a considerable variety of special symbols. Every character has a corresponding integer representation. The set of characters a computer uses together with the corresponding integer representations for those characters is called that computers character set. You can indicate a character value in a program simply by enclosing that character in single quotes, as in A
You can determine a characters integer equivalent by preceding that character with int as in
intA
An operator of this form is called a cast operator. Youll learn about cast operators in Chapter The following statement outputs a character and its integer equivalent:
System.out.printfThe character c has the value dnAintA;
When the preceding statement executes, it displays the character A and the value from the Unicode character set as part of the string. The format specifier c is a placeholder for a character in this case, the character A
Using statements similar to the one shown earlier in this exercise, write an application that displays the integer equivalents of some uppercase letters, lowercase letters, digits and special symbols. Display the integer equivalents of the following: A B C a b c $ and the blank character.
Separating the Digits in an Integer Write an application that inputs one number consisting of five digits from the user, separates the number into its individual digits and prints the digits separated from one another by three spaces each. For example, if the user types in the number the program should print
Assume that the user enters the correct number of digits. What happens when you enter a number with more than five digits? What happens when you enter a number with fewer than five digits? Hint: Its possible to do this exercise with the techniques you learned in this chapter. Youll need to use both division and remainder operations to pick off each digit.
Table of Squares and Cubes Using only the programming techniques you learned in this chapter, write an application that calculates the squares and cubes of the numbers from to and prints the resulting values in table format, as shown below.
number square cube
Negative Positive and Zero Values Write a program that inputs five numbers and determines and prints the number of negative numbers input, the number of positive numbers input and the number of zeros input.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
