New Semester
Started
Get
50% OFF
Study Help!
--h --m --s
Claim Now
Question Answers
Textbooks
Find textbooks, questions and answers
Oops, something went wrong!
Change your search query and then try again
S
Books
FREE
Study Help
Expert Questions
Accounting
General Management
Mathematics
Finance
Organizational Behaviour
Law
Physics
Operating System
Management Leadership
Sociology
Programming
Marketing
Database
Computer Network
Economics
Textbooks Solutions
Accounting
Managerial Accounting
Management Leadership
Cost Accounting
Statistics
Business Law
Corporate Finance
Finance
Economics
Auditing
Tutors
Online Tutors
Find a Tutor
Hire a Tutor
Become a Tutor
AI Tutor
AI Study Planner
NEW
Sell Books
Search
Search
Sign In
Register
study help
computer science
introduction to java programming and data structure
Introduction To Java Programming And Data Structures Comprehensive Version 12th Edition Y. Daniel Liang - Solutions
Write a program that displays three cards randomly selected from a deck of 52, as shown in Figure 14.43c. The card image files are named 1.png, 2.png, . . . , 52.png and stored in the image/card directory. All three cards are distinct and selected randomly. O O Exercise14_03 17 (c)
Write a program that displays a string “Welcome to Java” around the circle, as shown in Figure 14.44b. A00 Exercise14 05 JAVA COME (b) WEL
Write a program that displays a 10-by-10 square matrix, as shown in Figure 14.45a. Each element in the matrix is 0 or 1, randomly generated. Display each number centered in a text field. Use TextField’s setText method to set value 0 or 1 as a string. 800 Exercisel14.07 1 10 0 01 0 0 1 1101 a 11 1
Write a program that prompts the user to enter two strings, and reports whether the second string is a substring of the first string.Enter string s1: ABCDEnter string s2: BCBC is a substring of ABCDEnter string s1: ABCDEnter string s2: BDCBDC is not a substring of ABCD
A school has 100 lockers and 100 students. All lockers are closed on the first day of school. As the students enter, the first student, denoted as S1, opens every locker. Then the second student, S2, begins with the second locker, denoted as L2, and closes every other locker. Student S3 begins with
Write a program that passes a string to the command line and displays the number of uppercase letters in the string.
Write a program that passes an unspecified number of integers from command line and displays their total.
In Listing 7.8, you used selection sort to sort an array. The selection-sort method repeatedly finds the smallest number in the current array and swaps it with the first. Rewrite this program by finding the largest number and swapping it with the last. Write a test program that reads in 10 double
Write the following method that returns true if the list is already sorted in nondecreasing order:public static boolean isSorted(int[] list)Write a test program that prompts the user to enter a list and displays whether the list is sorted or not. Here is a sample run. Note that the program first
Write a program that prompts the user to enter the number of students, the students’ names, and their scores and prints student names in decreasing order of their scores. Assume the name is a string without spaces, use the Scanner’s next() method to read a name.
Write the following method that returns a random number between start and end, excluding the numbers.public static int getRandom(int start, int end, int... numbers)For example, invoking getRandom(1,100,4,8,95,93) returns a random number between 1 and 100 excluding 4,8,95,and 93. Write a test
Revise Programming Exercise 6.30 to run it 10,000 times and display the number of winning games.
Listing 2.7, ShowCurrentTime.java, displays the current time. Revise this example to display the current date and time. The calendar example in Listing 6.12, PrintCalendar.java, should give you some ideas on how to find the year, month, and day.
Implement the following two methods:/** Return true if the sum of every two sides is* greater than the third side. */public static boolean isValid(double side1, double side2, double side3)/** Return the area of the triangle. */public static double area(double side1, double side2, double side3)Write
Write a method that computes the commission, using the scheme in Programming Exercise 5.39. The header of the method is as follows:public static double computeCommission(double salesAmount)Write a test program that displays the following table: Sales Amount Commission 10000 900.0 15000 1500.0 20000
Write a program that prompts the user to enter the number of students and each student’s name and score, and finally displays the name of the student with the highest score. Use the next() method in the Scanner class to read a name, rather than using the nextLine() method. Assume that the number
Write a class that contains the following two methods:/** Convert from feet to meters */public static double footToMeter(double foot)/** Convert from meters to feet */public static double meterToFoot(double meter)The formula for the conversion is:meter = 0.305 * footfoot = 3.279 * meterWrite a test
Write a method to display a pattern as follows:The method header ispublic static void displayPattern(int n)Write a test program that prompts the user to enter a number n and invokes displayPattern( n) to display the pattern. 1 2 1 3 2 1 n n-1 ... 3 2 1
Write the methods with the following headers:// Return the reversal of an integer, e.g., reverse(456) returns 654public static int reverse(int number)// Return true if number is a palindromepublic static boolean isPalindrome(int number)Use the reverse method to implement isPalindrome. A number is a
Write a program that prompts the user to enter a string and displays the number of the uppercase letters in the string.Enter a string: Welcome to JavaThe number of uppercase letters is 2
Assume that the letters A, E, I, O, and U are vowels. Write a program that prompts the user to enter a string, and displays the number of vowels and consonants in the string.Enter a string: Programming is funThe number of vowels is 5The number of consonants is 11
that prompts the user to enter a string and displays the characters at odd positions. Here is a sample run:Enter a string: Beijing ChicagoBiigCiao
Write a program that prompts the user to enter a string and displays the string in reverse order.Enter a string: ABCDThe reversed string is DCBA
A short value is stored in 16 bits. Write a program that prompts the user to enter a short integer and displays the 16 bits for the integer. Here are sample runs:Enter an integer: 5The bits are 0000000000000101Enter an integer: –5The bits are 1111111111111011(Hint: You need to use the bitwise
Rewrite Programming Exercise 5.39 as follows:■■ Use a for loop instead of a do-while loop.■■ Let the user enter COMMISSION_SOUGHT instead of fixing it as a constant.
Write a program that prompts the user to enter a decimal integer then displays its corresponding binary value. Don’t use Java’s Integer. toBinaryString(int) in this program.
Write a program that prompts the user to enter the year and first day of the year and displays the calendar table for the year on the console. For example, if the user entered the year 2013, and 2 for Tuesday, January 1, 2013, your program should display the calendar for each month in the year, as
You can approximate e using the following summation:Write a program that displays the e value for i = 1, 2, …, and 20. Format the number to display 16 digits after the decimal point. (Hint: Because i! = i Χ (i - 1) Χ c Χ 2 Χ 1, thenInitialize e and item to be 1, and keep adding a new item to
Write a program to compute the following summation: 1 3 5 7 9. 11 95 97 3 7 9. 11 13 97 99 +
Another solution for Listing 5.9 to find the greatest common divisor of two integers n1 and n2 is as follows: First find d to be the minimum of n1 and n2, then check whether d, d–1, d–2, …, 2, or 1 is a divisor for both n1 and n2 in this order. The first such common divisor is the greatest
Write a program that displays all the numbers from 100 to 200 (10 per line) that are divisible by 5 or 6, but not both. Numbers are separated by exactly one space.
Write a program that displays all the numbers from 100 to 1,000 (10 per line) that are divisible by 5 and 6. Numbers are separated by exactly one space.
Write a program that prompts the user to enter the number of students and each student’s name and score, and finally displays the student with the highest score and the student with the second-highest score. Use the next() method in the Scanner class to read a name rather than using the
Write a program that prompts the user to enter a string and displays its length and its first character.
The international standard letter/number mapping found on the telephone is shown below:Write a program that prompts the user to enter a lowercase or uppercase letter and displays its corresponding number. For a nonletter input, display invalid input.Enter a letter: AThe corresponding number is
Write a program that prompts the user to enter a hex digit and displays its corresponding binary number in four digits. For example, hex digit 7 is 0111 in binary. Hex digits can be entered either in uppercase or lowercase. For an incorrect input, display invalid input. Here is a sample run:Enter a
Write a program that prompts the user to enter an integer between 0 and 15 and displays its corresponding hex number. For an incorrect input number, display invalid input. Here are some sample runs:Enter a decimal value (0 to 15): 11The hex value is BEnter a decimal value (0 to 15): 5The hex value
Suppose a pentagon is centered at (0, 0) with one point at the 0 o’clock position, as shown in Figure 4.4c. Write a program that prompts the user to enter the radius of the bounding circle of a pentagon and displays the coordinates of the five corner points on the pentagon from p1 to p5 in this
Write a program that generates three random points on a circle centered at (0, 0) with radius 40 and displays three angles in a triangle formed by these three points, as shown in Figure 4.4a. Display the angles in degrees. x = rX cos(a) and y = r X sin(a) 0 o'clock position P2 (x, y) 60 P30 O P1 65
A shipping company uses the following function to calculate the cost (in dollars) of shipping based on the weight of the package (in pounds).Write a program that prompts the user to enter the weight of the package and displays the shipping cost. If the weight is negative or zero, display a message
Revise Listing 3.8, Lottery.java, to generate a lottery of a threedigit integer. The program prompts the user to enter a three-digit integer and determines whether the user wins according to the following rules:1. If the user input matches the lottery number in the exact order, the award is
Write a program that prompts the user to enter an integer for today’s day of the week (Sunday is 0, Monday is 1, . . . , and Saturday is 6). Also prompt the user to enter the number of days after today for a future day and display the future day of the week. Here is a sample run:Enter today’s
How cold is it outside? The temperature alone is not enough to provide the answer. Other factors including wind speed, relative humidity, and sunshine play important roles in determining coldness outside. In 2001, the National Weather Service (NWS) implemented the new wind-chill temperature to
Write a program that prompts the user to enter the side of a hexagon and displays its area. The formula for computing the area of a hexagon iswhere s is the length of a side. Here is a sample run:Enter the length of the side: 5.5The area of the hexagon is 78.5918 3V3 Area
Write a program that reads in the radius and length of a cylinder and computes the area and volume using the following formulas:area = radius * radius * πvolume = area * lengthHere is a sample run:Enter the radius and length of a cylinder: 5.5 12 The area is 95.0331 The volume is 1140.4
Write a program that reads a Celsius degree in a double value from the console, then converts it to Fahrenheit, and displays the result. The formula for the conversion is as follows:fahrenheit = (9 / 5) * celsius + 32Hint: In Java, 9 / 5 is 1, but 9.0 / 5 is 1.8.Here is a sample run:Enter a degree
Showing 300 - 400
of 346
1
2
3
4
Step by Step Answers