Concept explainers
(Integer Value of a Character) Here’s 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 computer’s 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 character’s integer equivalent by preceding that character with (int), as in
(int) ‘A’
An operator of this form is called a cast operator. (You’ll learn about cast operators in Chapter 4.) The following statement outputs a character and its integer equivalent:
System.out.printf("The character %c has the value %d%n", ‘A’, ((int) ‘A’));
When the preceding statement executes, it displays the character A and the value 65 (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 0 1 2 $ * + / and the blank character.
Want to see the full answer?
Check out a sample textbook solutionChapter 2 Solutions
MyLab Programming with Pearson eText -- Access Code Card -- for Java How to Program, Early Objects
- What is the data type of the following expressions?arrow_forward9. answer previous chapters, you continued to modify the MarshallsRevenue program. Now, modify the program so that the major functions appear in the following individual methods: GetMonth - This method prompts for and returns the month GetNumMurals - This method prompts for and returns the number of murals scheduled and is called twice -- once for interior murals and once for exterior murals ComputeRevenue - This method accepts the number of interior and exterior murals scheduled, accepts the month they are scheduled, displays the interior and exterior prices, and then returns the total expected revenue DataEntry - This method fills an array with customer names and mural codes and is called twice -- once to fill the array of interior murals and once to fill the array of exterior murals GetSelectedMurals - This method continuously prompts for mural codes and displays jobs of the corresponding type until a sentinel value is entered. using System; using static System.Console; using…arrow_forwardExplain the difference between an argument and a parameter. Include a short Python example to illustrate the differencearrow_forward
- Question 10 Write a program in Java that finds the Least common multiple of 2 numbers,please include comments and fully explain what the code does because I am not really understanding what loops are doing ! (I need a manual way to calculate the lcm and not use a function(method) or "findlcm"..!arrow_forwardwhat is the value of the following expressions?arrow_forwardAnalyze the following statements carefully and decide whether the statements that appear after the code are true or false.arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning