All Matches
Solution Library
Expert Answer
Textbooks
Search Textbook questions, tutors and Books
Oops, something went wrong!
Change your search query and then try again
Toggle navigation
FREE Trial
S
Books
FREE
Tutors
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
Hire a Tutor
AI Tutor
New
Search
Search
Sign In
Register
study help
computer science
java concepts late objects
Questions and Answers of
Java Concepts Late Objects
Rewrite the following for loop into a while loop.int s = 0;for (int i = 1; i <= 10; i++){s = s + i;}
Write a program that first asks the user to type in today’s price of one dollar in Japanese yen, then reads U.S. dollar values and converts each to Japanese yen. Use 0 as the sentinel value to
Write a program that reads a number and prints all of its binary digits: Print the remainder number % 2, then replace the number with number / 2. Keep going until the number is 0. For example, if the
Write pseudocode for a program that reads a sequence of student records and prints the total score for each student. Each record has the student’s first and last name, followed by a sequence of
Currency conversion. Write a program that first asks the user to type today’s price for one dollar in Japanese yen, then reads U.S. dollar values and converts each to yen. Use 0 as a sentinel.
Write a program that prints all powers of 2 from 20 up to 220.
Write pseudocode for a program that reads a student record, consisting of the student’s first and last name, followed by a sequence of test scores and a sentinel of –1. The program should print
Write a program that reads an initial investment balance and an interest rate, then prints the number of years it takes for the investment to reach one million dollars.
Write a program that reads a sequence of words and then prints them in a box, with each word centered, like this: Hello I Java Iprogrammer|
Write a program that reads an integer n and a digit d between 0 and 9. Use one or more loops to count how many of the integers between 1 and n• start with the digit d.• end with the digit d.•
Write a program that reads a string and prints the longest sequence of vowels. If there are multiple sequences of the same length, print them all. For example, if the word is oiseau, print eau, and
Write pseudocode for a program that prints a calendar such as the following: Su M T W Th F Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
In the 17th century, the discipline of probability theory got its start when a gambler asked a mathematician friend to explain some observations about dice games. Why did he, on average, win a bet
Write a program that reads a string and prints the most frequently occurring letter. If there are multiple letters that occur with the same maximum frequency, print them all. For example, if the word
How many iterations do the following loops carry out? Assume that i is not changed in the loop body.a. for (int i = 1; i <= 10; i++) . . .b. for (int i = 0; i < 10; i++) . . .c. for (int i =
The Buffon Needle Experiment. The following experiment was devised by Comte Georges-Louis Leclerc de Buffon (1707–1788), a French naturalist. A needle of length 1 inch is dropped onto paper that is
Write a program that reads a word and prints all substrings, sorted by length. For example, if the user provides the input "rum", the program printsrumruumrum
Which loop statements does Java support? Give simple rules for when to use each loop type.
A simple random generator is obtained by the formula rnew = (a . rold + b)%mand then setting rold to rnew. If m is chosen as 232, then you can compute rnew = a . rold + bbecause the truncation
Write a program that reads a word and prints the number of syllables in the word. For this exercise, assume that syllables are determined as follows: Each sequence of adjacent vowels a e i o u y,
What is a sentinel value? Give a simple rule when it is appropriate to use a numeric sentinel value.
The Monty Hall Paradox. Marilyn vos Savant described the following problem (loosely based on a game show hosted by Monty Hall) in a popular magazine: “Suppose you’re on a game show, and you’re
Write a program that reads a word and prints the number of vowels in the word. For this exercise, assume that a e i o u y are vowels. For example, if the user provides the input "Harry", the program
What is an “off-by-one” error? Give an example from your own programming experience.
The Drunkard’s Walk. A drunkard in a grid of streets randomly picks one of four directions and stumbles to the next intersection, then again randomly picks one of four directions, and so on. You
Write a program that reads a word and prints the word in reverse. For example, if the user provides the input "Harry", the program prints yrraH
Write a program trace for the pseudocode in Exercise E4.6, assuming the input values are 4 7 –2 –5 0.
Write a program that reads a word and prints each character of the word on a separate line. For example, if the user provides the input "Harry", the program printsHarry
What is an infinite loop? On your computer, how can you terminate a program that executes an infinite loop?
Following Section 4.9, develop a program that reads a string and removes all duplicates. For example, if the input is Mississippi, print Misp. Start small and just print the first letter. Then print
Translate the following pseudocode for randomly permuting the characters in a string into a Java program.Read a word.Repeat word.length() timesPick a random position i in the word, but not the last
What do these loops print?a. for (int i = 1; i < 10; i++) { System.out.print(i + " "); }b. for (int i = 1; i < 10; i += 2) { System.out.print(i + " "); }c. for (int i = 10; i > 1; i--) {
Translate the following pseudocode for finding the minimum value from a set of inputs into a Java program.Set a Boolean variable "first" to true. If the scanner has more numbers Read the next value.
Provide trace tables for these loops.a. int i = 0; int j = 10; int n = 0;while (i < j) { i++; j--; n++; }b. int i = 0; int j = 0; int n = 0;while (i < 10) { i++; n = n + i + j; j++; }c. int i =
Write a loop that computesa. The sum of all even numbers between 2 and 100 (inclusive).b. The sum of all squares between 1 and 100 (inclusive).c. The sum of all odd numbers between a and b
Prime numbers. Write a program that prompts the user for an integer and then prints out all prime numbers up to that integer. For example, when the user enters 20, the program should
Write a program that reads a set of floating-point values. Ask the user to enter the values, then print• the average of the values.• the smallest of the values.• the largest of the values.•
Write a while loop that printsa. All squares less than n. For example, if n is 100, print 0 1 4 9 16 25 36 49 64 81.b. All positive numbers that are divisible by 10 and less than n. For example, if n
Factoring of integers. Write a program that asks the user for an integer and then prints out all its factors. For example, when the user enters 150, the program should print2355
What do these code snippets print?a. int result = 0;for (int i = 1; i <= 10; i++) { result = result + i; }System.out.println(result);b. int result = 1;for (int i = 1; i <= 10; i++) { result = i
The Fibonacci numbers are defined by the sequenceReformulate that asfold1 = 1;fold2 = 1;fnew = fold1 + fold2;After that, discard fold2, which is no longer needed, and set fold2 to fold1 and fold1 to
Write a program that prompts the user to provide a single character from the alphabet. Print Vowel or Consonant, depending on the user input. If the user input is not a letter (between a and z or A
Write programs that read a line of input as a string and printa. Only the uppercase letters in the string.b. Every second letter of the string.c. The string, with all vowels replaced by an
What do these loops print?a. int i = 0; int j = 10;while (i < j) { System.out.println(i + " " + j); i++; j--; }b. int i = 0; int j = 10;while (i < j) { System.out.println(i + j); i++; j++; }
Mean and standard deviation. Write a program that reads a set of floating-point data values. Choose an appropriate mechanism for prompting for the end of the data set. When all values have been read,
Write programs that read a sequence of integer inputs and printa. The smallest and largest of the inputs.b. The number of even and odd inputs.c. Cumulative totals. For example, if the input is 1 7 2
Given the variablesString stars = "*****";String stripes = "=====";what do these loops print?a. int i = 0;while (i < 5){System.out.println(stars.substring(0, i));i++;}b. int i = 0;while (i <
Write programs with loops that computea. The sum of all even numbers between 2 and 100 (inclusive).b. The sum of all squares between 1 and 100 (inclusive).c. All powers of 2 from 20 up to 220.d. The
What is wrong with the following program?System.out.print("Enter the number of quarters: ");int quarters = in.nextInt();if (in.hasNextInt()){total = total + quarters * 0.25;System.out.println("Total:
Simplify the following statements. Here, b is a variable of type boolean and n is a variable of type int.a. if (n == 0) { b = true; } else { b = false; }b. if (n == 0) { b = false; } else { b = true;
Simplify the following expressions. Here, b is a variable of type boolean.a. b == trueb. b == falsec. b != trued. b != false
Suppose the value of b is false and the value of x is 0. What is the value of each of the following expressions?a. b && x == 0b. b || x == 0c. !b && x == 0d. !b || x == 0e. b
The average person can jump off the ground with a velocity of 7 mph without fear of leaving the planet. However, if an astronaut jumps with this velocity while standing on Halley’s Comet, will the
The “advanced search” feature of many search engines allows you to use Boolean operators for complex queries, such as “(cats OR dogs) AND NOT pets”. Contrast these search operators with the
A mass m = 2 kilograms is attached to the end of a rope of length r = 3 meters. The mass is whirled around at high speed. The rope can withstand a maximum tension of T = 60 Newtons. Write a program
True or false? A && B is the same as B && A for any Boolean conditions A and B.
Crop damage due to frost is one of the many risks confronting farmers. The figure below shows a simple alarm circuit designed to warn of frost. The alarm circuit uses a device called a thermistor to
Complete the following truth table by finding the truth values of the Boolean expressions for all combinations of the Boolean inputs p, q, and r. (p && q) || !r !(p && (q || !r)) false false false
The electric circuit shown below is designed to measure the temperature of the gas in a chamber.The resistor R represents a temperature sensor enclosed in the chamber. The resistance R, in Ω, is
Make up a Java code example that shows the dangling else problem using the following statement: A student with a GPA of at least 1.5, but less than 2, is on probation. With less than 1.5, the student
Sound level L in units of decibel (dB) is determined by L = 20 log10(p/p0) where p is the sound pressure of the sound (in Pascals, abbreviated Pa), and p0 is a reference sound pressure equal to 20 ×
A minivan has two sliding doors. Each door can be opened by either a dashboard switch, its inside handle, or its outside handle. However, the inside handles do not work if a child lock switch is
Repeat Exercise P3.21, modifying the program so that it first asks the user whether the input will be a wavelength or a frequency.Data from Exercise P3.21,Write a program that prompts the user for a
Give an example of an if/else if/else sequence where the order of the tests does not matter. Give an example where the order of the tests matters.
Repeat Exercise P3.21, modifying the program so that it prompts for the frequency instead.Data from Exercise P3.21,Write a program that prompts the user for a wavelength value and prints a
Explain the difference between an if/else if/else sequence and nested if statements. Give an example of each.
Write a program that prompts the user for a wavelength value and prints a description of the corresponding part of the electromagnetic spectrum, as given in the following table. Electromagnetic
Of the following pairs of strings, which comes first in lexicographic order?a. "Tom", "Jerry"b. "Tom", "Tomato"c. "church", "Churchill"d. "car manufacturer", "carburetor"e. "Harry", "hairy"f. "Java",
A supermarket awards coupons depending on how much a customer spends on groceries. For example, if you spend $50, you will get a coupon worth eight percent of that amount. The following table shows
Explain how the lexicographic ordering of strings in Java differs from the ordering of words in a dictionary or telephone book. Hint: Consider strings such as IBM, wiley.com, Century 21, and
Calculating the tip when you go to a restaurant is not difficult, but your restaurant wants to suggest a tip according to the service diners receive. Write a program that calculates a tip according
Write pseudocode for a program that assigns letter grades for a quiz, according to the following table:Score Grade90-100 ....... A80-89 ......... B70-79 ......... C60-69
When you use an automated teller machine (ATM) with your bank card, you need to use a personal identification number (PIN) to access your account. If a user fails more than three times when entering
Write a program that asks the user to enter a month (1 for January, 2 for February, and so on) and then prints the number of days in the month. For February, print “28 or 29 days”. Enter a month:
Write pseudocode for a program that prompts the user for a month and day and prints out whether it is one of the following four holidays:• New Year’s Day (January 1)• Independence Day (July
Write a program that prompts the user to provide a single character from the alphabet. Print Vowel or Consonant, depending on the user input. If the user input is not a letter (between a and z or A
Develop a set of test cases for the algorithm in Exercise E3.14.Data from Exercise E3.14.Draw a flowchart for the algorithm in Exercise E3.13. Data from Exercise E3.13.Draw a flowchart for the
Write a unit conversion program that asks the users from which unit they want to convert (fl. oz, gal, oz, lb, in, ft, mi) and to which unit they want to convert (ml, l, g, kg, mm, cm, m, km). Reject
Develop a set of test cases for the algorithm in Exercise R3.12.Data from Exercise R3.12.In a scheduling program, we want to check whether two appointments overlap. For simplicity, appointments start
French country names are feminine when they end with the letter e, masculine otherwise, except for the following which are masculine even though they end with e:• le Belize• le Cambodge• le
Write a program that reads in two floating-point numbers and tests whether they are the same up to two decimal places. Here are two sample runs. Enter two floating-point numbers: 2.0 1.99998 They are
Draw a flowchart for the algorithm in Exercise E3.14.Data from Exercise E3.14.Draw a flowchart for the algorithm in Exercise E3.13.Data from Exercise E3.13.Draw a flowchart for the algorithm in
A year with 366 days is called a leap year. Leap years are necessary to keep the calendar synchronized with the sun because the earth revolves around the sun once every 365.25 days. Actually, that
The following algorithm yields the season (Spring, Summer, Fall, or Winter) for a given month and day.If month is 1, 2, or 3, season = "Winter"Else if month is 4, 5, or 6, season = "Spring"Else if
Draw a flowchart for the algorithm in Exercise E3.13.Data from Exercise E3.13.Draw a flowchart for the algorithm in Exercise R3.12.Data from Exercise R3.12.In a scheduling program, we want to check
Roman numbers. Write a program that converts a positive integer into the Roman number system. The Roman number system has digitsI ........1V ........5X ........10L ........50C ........100D
Write a program that reads in three floating-point numbers and prints the largest of the three inputs. For example: Please enter three numbers: 4 9 2.5 The largest number is 9.
When two points in time are compared, each given as hours (in military time, ranging from 0 and 23) and minutes, the following pseudocode determines which comes first.If hour1 < hour2time1 comes
Draw a flowchart for the algorithm in Exercise R3.12.Data from Exercise R3.12.In a scheduling program, we want to check whether two appointments overlap. For simplicity, appointments start at a full
Write a program that reads in the x- and y-coordinates of four corner points of a quadrilateral and prints out whether it is a square, a rectangle, a trapezoid, a rhombus, or none of those shapes.
Add error handling to Exercise E3.11. If the user does not enter a number when expected, or provides an invalid unit for the altitude, print an error message and end the program.Data from Exercise
In a scheduling program, we want to check whether two appointments overlap. For simplicity, appointments start at a full hour, and we use military time (with hours 0–24). The following pseudocode
Write a program that reads in the x- and y-coordinates of three corner points of a triangle and prints out whether it has an obtuse angle, a right angle, or only acute angles.
The boiling point of water drops by about one degree centigrade for every 300 meters (or 1,000 feet) of altitude. Improve the program of Exercise E3.10 to allow the user to supply the altitude in
Write a program that reads in the x- and y-coordinates of two corner points of a rectangle and then prints out whether the rectangle is a square, or is in “portrait” or “landscape”
Write a program that reads a temperature value and the letter C for Celsius or F for Fahrenheit. Print whether water is liquid, solid, or gaseous at the given temperature at sea level.
Each square on a chess board can be described by a letter and number, such as g5 in this example:The following pseudocode describes an algorithm that determines whether a square with a given letter
The TaxCalculator.java program uses a simplified version of the 2008 U.S. income tax schedule. Look up the tax brackets and rates for the current year, for both single and married filers, and
A compass needle points a given number of degrees away from North, measured clockwise. Write a program that reads the angle and prints out the nearest compass direction; one of N, NE, E, SE, S, SW,
It is easy to confuse the = and == operators. Write a test program containing the statementif (floor = 13)What error message do you get? Write another test program containing the statementcount ==
Showing 600 - 700
of 835
1
2
3
4
5
6
7
8
9