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
building java programs a back to basics approach
Building Java Programs A Back To Basics Approach 5th Edition Stuart Reges, Marty Stepp - Solutions
Write a method called numUnique that takes three integers as parameters and returns the number of unique integers among the three. For example, the call numUnique(18, 3, 4) should return 3 because the parameters have three different values. By contrast, the call numUnique(6, 7, 6) should return 2
What output is produced by the following program? 1 public class CharMystery { public static void printRange (char startLetter, char endLetter) { for (char letter = startLetter; letter
Write a method called perfectNumbers that accepts an integer maximum as its parameter and prints all “perfect numbers” up to and including that maximum. A perfect number is an integer that is equal to the sum of its proper factors, that is, all numbers that evenly divide it other than 1 and
Write an if statement that tests to see whether a String begins with a capital letter.
Write a method called printAcronym that accepts a string as its parameter and prints the first letter of each word of the string as an acronym. For example, the call of printAcronym("Breath of the Wild") should print "BotW" . You may assume that the string contains at least one word and does not
What is wrong with the following code, which attempts to count the number occurrences of the letter 'e' in a String , case-insensitively? int count = 0; for (int i = 0; i < s.length (); i++) { if (s.charAt (i).toLowerCase () 'e') { %3D%3D count++; }
Consider a String stored in a variable called name that stores a person’s first and last name (e.g., “Marla Singer”). Write the expression that would produce the last name followed by the first initial (e.g., “Singer, M.”).
Write code to examine a String and determine how many of its letters come from the second half of the alphabet (that is, have values of 'n' or subsequent letters). Compare case-insensitively, such that values of 'N' through 'Z' also count. Assume that every character in the String is a letter.
Consider a method printTriangleType that accepts three integer arguments representing the lengths of the sides of a triangle and prints the type of triangle that these sides form. The three types are equilateral, isosceles, and scalene. An equilateral triangle has three sides of the same length, an
Consider a method getGrade that accepts an integer representing a student’s grade percentage in a course and returns that student’s numerical course grade. The grade can be between 0.0 (failing) and 4.0 (perfect). What are the preconditions of such a method?
The following method attempts to return the median (middle) of three integer values, but it contains logic errors. In what cases does the method return an incorrect result? How can the code be fixed? public static int medianof3 (int n1, int n2, int n3) { if (nl < n2) { if (n2 < n3) { return n2; }
Write a method called hasAnOddDigit that returns whether a given positive integer has at least one digit whose value is odd. Return true if the number has at least one odd digit and false if none of its digits are odd. For example, the call hasAnOddDigit(4822116) should return true and
Write a piece of code that prompts the user for a number and then prints a different message depending on whether the number was an integer or a real number. Here are two sample dialogues:Type a number: 42.5You typed the real number 42.5Type a number: 3You typed the integer 3
Write a method called charsSorted that accepts a string as its parameter and returns true if the characters in the string appear in sorted alphabetical order. For example, the calls of charsSorted("abcde") and charsSorted("bins") should return true, but the call of charsSorted("beads") should
Write code that prompts for three integers, averages them, and prints the average. Make your code robust against invalid input.
Identify the various assertions in the following code as being always true, never true, or sometimes true and sometimes false at various points in program execution. The comments indicate the points of interest:Categorize each assertion at each point with ALWAYS, NEVER, or SOMETIMES. public static
Identify the various assertions in the following code as being always true, never true, or sometimes true and sometimes false at various points in program execution. The comments indicate the points of interest:Categorize each assertion at each point with ALWAYS, NEVER, or SOMETIMES. public static
Identify the various assertions in the following code as being always true, never true, or sometimes true and sometimes false at various points in program execution. The comments indicate the points of interest:Categorize each assertion at each point with ALWAYS, NEVER, or SOMETIMES. public static
Write a program to spell out MISSISSIPPI using block letters like the following (one per line): M IIIII sssss PPPPPP MM MM S P M M M M I P P M M M Sssss PPPPPP M M S M M S P M M IIIII SSSss P
Which of the following is the correct syntax to output a message?a. System.println(Hello, world!);b. System.println.out('Hello, world!');c. System.println("Hello, world!");d. System.out.println("Hello, world!");e. Out.system.println"(Hello, world!)";
Write a for loop that produces the following output:1 4 9 16 25 36 49 64 81 100For added challenge, try to modify your code so that it does not need to use the * multiplication operator.
What is the result of the following expression?1 + 2 * 3 + 7 * 2 % 5a. 1b. 2c. 5d. 11e. 21
Imagine you are writing a personal fitness program that stores the user’s age, gender, height (in feet or meters), and weight (to the nearest pound or kilogram). Declare variables with the appropriate names and types to hold this information.
It’s common to print a rotating, increasing list of single-digit numbers at the start of a program’s output as a visual guide to number the columns of the output to follow. With this in mind, write nested for loops to produce the following output, with each line 60 characters wide:
What is the output of the following sequence of loops? for (int i = 1; i
What is the output of the following sequence of loops? for (int i = 1; i
Write a program that produces the following output using nested for loops. Use a class constant to make it possible to change the number of stairs in the figure. ******* /ハ* ****** ****** /ハ * ****** /ハ* 大 大★★★★★
What are the values of a , b , and c after the following statements?int a = 5;int b = 10;int c = b;a = a + 1;b = b - 1;c = c + a;
Rewrite the code from the previous exercise to be shorter, by declaring the variables together and by using the special assignment operators (e.g., += , −= , *= , and /= ) as appropriate.Data from Previous Problemint first = 8;int second = 19;first = first + second;second = first − second;first
What are the values of i , j , and k after the following statements?int i = 2;int j = 3;int k = 4;int x = i + j + k;i = x - i - j;j = x - j - k;k = x - i - k;
What is the output from the following code?int max;int min = 10;max = 17 − 4 / 10;max = max + 6;min = max − min;System.out.println(max * 2);System.out.println(max + min);System.out.println(max);System.out.println(min);
Use your pseudocode from the previous exercise to write a Java program called Window that produces the preceding figure as output. Use nested for loops to print the repeated parts of the figure. Once you get it to work, add a class constant so that the size of the figure can be changed simply by
The following program redundantly repeats the same expressions many times. Modify the program to remove all redundant expressions using variables of appropriate types. public class ComputePay { public static void main (String [] args) { 3. // Calculate pay at work based on hours worked each day 4
Write a Java program called StarFigure that produces the following output. Use nested for loops to capture the structure of the figure. //// ★★素* **1* // /*** ******* ////************ **\\\\ *★★*大* *** ** ** ****
The following program redundantly repeats the same expressions many times. Modify the program to remove all redundant expressions using variables of appropriate types. // This program computes the total amount owed for a meal, // assuming 8% tax and a 15% tip. public class Receipt { public static
Modify your DollarFigure program from the previous exercise to become a new program called DollarFigure2 that uses a global constant for the figure’s height. (You may want to make loop tables first.) The previous output used a constant height of 7.Data from Previous ExerciseWrite a Java program
Complete the code for the following for loop:so that it prints the following numbers, one per line:−41432506886 for (int i 1; i
Write a complete Java program called Stewie that prints the following output: I| victory is mine! ||
Why do computers use binary numbers?
Write a complete Java program called Spikey that prints the following output: W// /// 1/ハ ハ
Convert each of the following decimal numbers into its equivalent binary number:a. 6b. 44c. 72d. 131
Sometimes we write similar letters to different people. For example, you might write to your parents to tell them about your classes and your friends and to ask for money; you might write to a friend about your love life, your classes, and your hobbies; and you might write to your brother about
Write a complete Java program called WellFormed that prints the following output:
What is the decimal equivalent of each of the following binary numbers?a. 100b. 1011c. 101010d. 1001110
Write a program that produces as output the lyrics to the repetitive song, “There Was an Old Lady Who Swallowed a Fly,” by Simms Taback. Use methods for each verse and the refrain. Your methods should capture the structure of the song’s verses as well as avoid redundancy between similar lines
Write a complete Java program called Difference that prints the following output:
In your own words, describe an algorithm for baking cookies. Assume that you have a large number of hungry friends, so you’ll want to produce several batches of cookies!
Write a program that produces as output the words of “The Twelve Days of Christmas.” (Static methods simplify this task.) Here are the first two verses and the last verse of the song: On the first day of Christmas, my true love sent to me a partridge in a pear tree. On the second day of
Write a complete Java program called MuchBetter that prints the following output: A "quoted" String is 'much' better if you learn the rules of "escape sequences." Also, "" represents an empty String. Don't forget: use \" instead of " " is not the same as "
What is the difference between the file MyProgram.java and the file MyProgram.class?
Write a program that produces as output the words of “The House That Jack Built.” Use methods for each verse and for repeated text. Here are lyrics to use: This is the house that Jack built. This is the malt That lay in the house that Jack built. This is the rat, That ate the malt That lay in
Write a complete Java program called Meta whose output is the text that would be the source code of a Java program that prints “Hello, world!” as its output.
Which of the following can be used in a Java program as identifiers? println first-name AnnualSalary "hello" АВС 42isTheAnswer for sum of data average В4
Write a program that produces as output the words of the song, “Bought Me a Cat.” Use methods for each verse and for repeated text.
Write a complete Java program called Mantra that prints the following output. Use at least one static method besides main. There's one thing every coder must understand: The System.out.println command. There's one thing every coder must understand: The System.out.println command.
Write a program that produces as output the words of the following silly song. Use methods for each verse and for repeated text. Here are the song’s complete lyrics:
Write a complete Java program called Stewie2 that prints the following output. Use at least one static method besides main. /// //// ///// || Victory is mine! I| || Victory is mine! || II Victory is mine! |1 || victory is mine! |1 || Victory is mine! ||
What is the output produced from the following statements?System.out.println("\"Quotes\"");System.out.println("Slashes \\//");System.out.println("How '\"confounding' \"\\\" it is!");
Write a program called Egg that displays the following output:
What is the output produced from the following statements?System.out.println("name\tage\theight");System.out.println("Archie\t17\t5'9\"");System.out.println("Betty\t17\t5'6\"");System.out.println("Jughead\t16\t6'");
What is the output produced from the following statements?System.out.println("Shaq is 7'1");System.out.println("The string \"\" is an empty message.");System.out.println("\\'\"\"");
Modify the program from the previous exercise to become a new program Egg2 that displays the following output. Use static methods as appropriate.
What is the output produced from the following statements?System.out.println("\ta\tb\tc");System.out.println("\\\\");System.out.println("'");System.out.println("\"\"\"");System.out.println("C:\nin\the downward spiral");
Write a Java program called TwoRockets that generates the following output. Use static methods to show structure and eliminate redundancy in your solution. Note that there are two rocket ships next to each other. What redundancy can you eliminate using static methods? What redundancy cannot be
What is the output produced from the following statements?System.out.println("Dear \"DoubleSlash\" magazine,");System.out.println();System.out.println("\tYour publication confuses me. Is it");System.out.println("a \\\\ slash or a ////
Write a program called FightSong that produces this output. Use at least two static methods to show structure and eliminate redundancy in your solution. Go, team, go! You can do it. Go, team, go! You can do it. You're the best, In the West. Go, team, go! You can do it. Go, team, go! You can do it.
Write a Java program called StarFigures that generates the following output. Use static methods to show structure and eliminate redundancy in your solution. ***** ***** 大 大★★★* ***** ***** ***** 大才* ***** 大 de
What series of println statements would produce the following output?"Several slashes are sometimes seen,"said Sally. "I've said so." See?\ / \\ // \\\ ///
What series of println statements would produce the following output?This is a test of yourknowledge of "quotes" usedin 'string literals.'You're bound to "get it right"if you read the section on''quotes.''
Write a Java program called Lanterns that generates the following output. Use static methods to show structure and eliminate redundancy in your solution. ★大 ** ***** **** オ ***** ********* ***** 大★大大大大*★* ***** ***** オ★★★★
Write a println statement that produces the following output:/ \ // \\ /// \\\
Write a Java program called EggStop that generates the following output. Use static methods to show structure and eliminate redundancy in your solution. STOP
Rewrite the following code as a series of equivalent System.out.println statements (i.e., without any System.out.print statements):System.out.print("Twas ");System.out.print("brillig and the");System.out.println(" ");System.out.print(" slithy toves did");System.out.print("
Write a program called Shining that prints the following line of output 1000 times:All work and no play makes Jack a dull boy.You should not write a program that uses 1000 lines of source code; use methods to shorten the program. What is the shortest program you can write that will produce the 1000
What is the output of the following program? Note that the program contains several comments. public class Commentary { 2 public static void main (String [] args) { System.out.println ("some lines of code"); System.out.println ("have // characters on them"); System.out.println ("which means "); //
Write a program called FarewellGoodBye that prints the following lyrics. Use static methods to show structure and eliminate redundancy in your solution. Farewell, goodbye, au revoir, good night! It's time, to go, and I'll be out of sight! Farewell, goodbye, au revoir, take care! I'll say, goodbye,
Name the three errors in the following program: public MyProgram { public static void main (String [] args) { System.out.println("This is a test of the") System.out.Println ("emergency broadcast system.");
Name the four errors in the following program:
Name the four errors in the following program: public class Famous Speech public static void main (String []) { System.out.println ("Four score and seven years ago, "); System.out.println ("our fathers brought forth on"); System.out.println ("this continent a new nation"); System.out.println
Which of the following method headers uses the correct syntax?a. Public static example() {b. Public static void example() {c. Public void static example() {d. Public static example void[] {e. Public void static example{} (
What is the output of the following program? (You may wish to draw a structure diagram first.) public class Tricky { public static void main (String [] args) { messagel (); message2 (); System.out.println ("Done with main."); public static void messagel () { System.out.println ("This is
What is the output of the following program? (You may wish to draw a structure diagram first.) public class Strange { public static void first () { System.out.println ("Inside first method"); public static void second () { System.out.println ("Inside second method"); first (); public static void
What would have been the output of the preceding program if the third method had contained the following statements? public static void third () { first (); second (); System.out.println ("Inside third method");
What would have been the output of the Strange program if the main method had contained the following statements? (Use the original version of third, not the modified version from the most recent exercise.) public static void main (String[] args) { second () ; first (); second () ; third ();
What is the output of the following program? (You may wish to draw a structure diagram first.) public class Confusing { public static void method2 () { method1 (); System.out.println ("I am method 2."); public static void method3 () { method2 () ; System.out.println ("I am method 3."); method1 () ;
What would have been the output of the preceding program if the method3 method had contained the following statements? public static void method3 () { method1 (); method2 () ; System.out.println ("I am method 3."):
What would have been the output of the Confusing program if the main method had contained the following statements? (Use the original version of method3 , not the modified version from the most recent exercise.) public static void main (String [] args) { method2 (): method1 (); method3 () ; method2
The following program contains at least 10 syntax errors. What are they?
Consider the following program, saved into a file named Example.java:What would happen if each of the following changes were made to the Example program? For example, would there be no effect, a syntax error, or a different program output? Treat each change independently of the others.a. Change
The following program is legal under Java’s syntax rules, but it is difficult to read because of its layout and lack of comments. Reformat it using the rules given in this chapter, and add a comment header at the top of the program. public class GiveAdvice( public static void main (String[]args)
The following program is legal under Java’s syntax rules, but it is difficult to read because of its layout and lack of comments. Reformat it using the rules given in this chapter, and add a comment header at the top of the program. public class Messy{public static void main (String [largs)
In physics, a common useful equation for finding the position of a body in linear motion at a given time , based on its initial position, initial velocity , and rate of acceleration , is the following:Write code to declare variables for , , , and , and then write the code to compute on the basis of
Which of the following are legal int literals?22 1.5 −1 2.3 10.0 5. −6875309 '7'
The Fibonacci numbers are a sequence of integers in which the first two elements are 1, and each following element is the sum of the two preceding elements. The mathematical definition of each kth Fibonacci number is the following:The first 12 Fibonacci numbers are1 1 2 3 5 8 13 21 34 55 89
Trace the evaluation of the following expressions, and give their resulting values:a. 2 + 3 * 4 − 6b. 14 / 7 * 2 + 30 / 5 + 1c. (12 + 3) / 4 * 2d. (238 % 10 + 3) % 7e. (18 − 7) * (43 % 10)f. 2 + 19 % 5 − (11 * (5 / 2))g. 813 % 100 / 3 + 2.4h. 26 % 10 % 4 * 3i. 22 + 4 * 2j. 23 % 8 % 3k. 12 −
Trace the evaluation of the following expressions, and give their resulting values:a. 4.0 / 2 * 9 / 2b. 2.5 * 2 + 8 / 5.0 + 10 / 3c. 12 / 7 * 4.4 * 2 / 4d. 4 * 3 / 8 + 2.5 * 2e. (5 * 7.0 / 2 − 2.5) / 5 * 2f. 41 % 7 * 3 / 5 + 5 / 2 * 2.5g. 10.0 / 2 / 4h. 8 / 5 + 13 / 2 / 3.0i. (2.5 + 3.5) / 2j. 9
Write nested for loops to produce the following output:********************
Write a program that produces the following hourglass figure as its output using nested for loops: \::/ 1::\ 1:: 7::::: 1::::::
Write nested for loops to produce the following output:***************
Trace the evaluation of the following expressions, and give their resulting values:a. 2 + 2 + 3 + 4b. "2 + 2" + 3 + 4c. 2 + " 2 + 3 " + 4d. 3 + 4 + " 2 + 2"e. "2 + 2 " + (3 + 4)f. "(2 + 2) " + (3 + 4)g. "hello 34 " + 2 * 4
Showing 900 - 1000
of 1041
1
2
3
4
5
6
7
8
9
10
11
Step by Step Answers