Java Reference
In-Depth Information
2.15 (Arithmetic) Write an application that asks the user to enter two integers, obtains them
from the user and prints their sum, product, difference and quotient (division). Use the techniques
shown in Fig. 2.7.
2.16 (Comparing Integers) Write an application that asks the user to enter two integers, obtains
them from the user and displays the larger number followed by the words "is larger" . If the num-
bers are equal, print the message "These numbers are equal" . Use the techniques shown in Fig. 2.15.
2.17 (Arithmetic, Smallest and Largest) Write an application that inputs three integers from the
user and displays the sum, average, product, smallest and largest of the numbers. Use the techniques
shown in Fig. 2.15. [ Note: The calculation of the average in this exercise should result in an integer
representation of the average. So, if the sum of the values is 7, the average should be 2, not
2.3333….]
2.18 (Displaying Shapes with Asterisks) Write an application that displays a box, an oval, an ar-
row and a diamond using asterisks ( * ), as follows:
********* *** * *
* * * * *** * *
* * * * ***** * *
* * * * * * *
* * * * * * *
* * * * * * *
* * * * * * *
* * * * * * *
********* *** * *
2.19 What does the following code print?
System.out.printf( "*%n**%n***%n****%n*****%n" );
2.20 What does the following code print?
System.out.println( "*" );
System.out.println( "***" );
System.out.println( "*****" );
System.out.println( "****" );
System.out.println( "**" );
2.21 What does the following code print?
System.out.print( "*" );
System.out.print( "***" );
System.out.print( "*****" );
System.out.print( "****" );
System.out.println( "**" );
2.22 What does the following code print?
System.out.print( "*" );
System.out.println( "***" );
System.out.println( "*****" );
System.out.print( "****" );
System.out.println( "**" );
2.23 What does the following code print?
System.out.printf( "%s%n%s%n%s%n", "*", "***", "*****" );
2.24 (Largest and Smallest Integers) Write an application that reads five integers and determines
and prints the largest and smallest integers in the group. Use only the programming techniques you
learned in this chapter.
Search WWH ::




Custom Search