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
Ask a Question
Search
Search
Sign In
Register
study help
Computer science
algorithm design
introduction to programming
Questions and Answers of
Introduction To Programming
I noticed that the argument to the equals() method in String and Color is of type Object. Shouldn’t the argument be of type String and Color, respectively?
Why does the String method call s.substring(i, j) return the substring of s starting at index i and ending at j-1 (and not j)?
Why is the image-processing data type named Picture instead of Image?
Do instance variables have default initial values that we can depend upon?
What is null?
Suppose I do not include a toString() method. What happens if I try to print an object of that type with StdOut.println()?
Are there other kinds of variables besides argument, local, and instance variables in a class?
Mandelbrot creates tens of millions of Complex objects. Doesn’t all that objectcreation overhead slow things down?
What happens if I try to access a private instance variable or method from a class in another file?
What is a deprecated method?
What is wrong with the following implementation of equals() for Complex?public boolean equals(Complex that){return (this.re == that.re) && (this.im == that.im);}
What is wrong with the following of hashCode() for Complex?public int hashCode(){ return -17; }
In some cases a lambda expression does nothing more than call a named method in another class. Is there any shorthand for doing this?
The Universe API is certainly small. Why not just implement that code in a main() test client for Body?
Why is forceFrom() an instance method? Wouldn’t it be better for it to be a static method that takes two Body objects as arguments?
How do I find out how long it takes to add or multiply two floating-point numbers on my system?
How much time do string operations take?
How do I determine how much memory is available for my Java programs?
Why do we need to go to such lengths to prove a program correct?
Why do I get a unchecked or unsafe operation warning when compiling Insertion. java and Merge. java?
Why not have a single Co17ection data type that implements methods to add items, remove the most recently inserted item, remove the least recently inserted item, remove a random item, iterate over
Why is the val instance variable in the nested Node class in HashST declared to be of type Object instead of Value?
How many different graphs are there with \(V\) given vertices?
Can a graph have a vertex that is not adjacent to any other vertex?
Why are Graph and PathFinder in separate classes? Wouldn't it make more sense to include the PathFinder methods in the Graph API?
Is there anything wrong with allocating and deallocating thousands of Color objects, as in Grayscale (PROGRAM 3.1.4)? Program 3.1.4 Converting color to grayscale import java.awt.Color; public class
These computations with plus() and times() seem rather clumsy. Is there some way to use symbols like + and * in expressions involving objects where they make sense, such as Complex and Vector, so
Can I have a static method in a class that implements a data type?
Can I initialize an instance variable to a value other than the default value when I declare it?
Must every class have a constructor?
Write a program that prints the Hello, World message 10 times.
Describe what happens if you omit the following in HelloWorld.java:a. publicb. staticc. voidd. args
Describe what happens if you misspell (by, say, omitting the second letter)the following in HelloWorld.java:a. publicb. staticc. voidd. args
Describe what happens if you put the double quotes in the print statement of HelloWorld.java on different lines, as in this code fragment:System.out.println("Hello, World");
Describe what happens if you try to execute UseArgument with each of the following command lines:a. java UseArgument javab. java UseArgument @!&^%c. java UseArgument 1234d. java UseArgument.java
Modify UseArgument.java to make a program UseThree.java that takes three names as command-line arguments and prints a proper sentence with the names in the reverse of the order given, so that, for
Suppose that a and b are int variables. What does the following sequence of statements do?int t = a; b = t; a = b;
Write a program that uses Math.sin() and Math.cos() to check that the value of cos2θ + sin2θ is approximately 1 for any θ entered as a command-line argument.Just print the value. Why are the
Suppose that a and b are boolean variables. Show that the expression(!(a && b) && (a || b)) || ((a && b) || !(a || b))evaluates to true.
Suppose that a and b are int variables. Simplify the following expression:(!(a < b) && !(a > b)).
The exclusive or operator ^ for boolean operands is defined to be true if they are different, false if they are the same. Give a truth table for this function.
Why does 10/3 give 3 and not 3.333333333?
What does each of the following print?a. System.out.println(2 + "bc");b. System.out.println(2 + 3 + "bc");c. System.out.println((2+3) + "bc");d. System.out.println("bc" + (2+3));e.
Explain how to use PROGRAM 1.2.3 to find the square root of a number.PROGRAM 1.2.3 Suppose that a and b are boolean variables. Show that the expression(!(a &&b) && (a || b)) || ((a &&b) || !(a ||
What does each of the following print?a. System.out.println('b');b. System.out.println('b' + 'c');c. System.out.println((char) ('a' + 4));Explain each outcome.
Suppose that a variable a is declared as int a = 2147483647 (or equivalently, Integer.MAX_VALUE). What does each of the following print?a. System.out.println(a);b. System.out.println(a+1);c.
Suppose that a variable a is declared as double a = 3.14159. What does each of the following print?a. System.out.println(a);b. System.out.println(a+1);c. System.out.println(8/(int) a);d.
Describe what happens if you write sqrt instead of Math.sqrt in PROGRAM 1.2.3.PROGRAM 1.2.3.Suppose that a and b are boolean variables. Show that the expression(!(a &&b) && (a || b)) || ((a &&b) ||
Evaluate the expression (Math.sqrt(2) * Math.sqrt(2) == 2).
Write a program that takes two positive integers as command-line arguments and prints true if either evenly divides the other.
Write a program that takes three positive integers as command-line arguments and prints false if any one of them is greater than or equal to the sum of the other two and true otherwise. (Note : This
A physics student gets unexpected results when using the code double force = G * mass1 * mass2 / r * r;to compute values according to the formula F = Gm1m2 / r2. Explain the problem and correct the
Give the value of the variable a after the execution of each of the following sequences of statements: int a = 1; a= a + a; a = a +a; a= a +a; boolean a true; a = la; a = !a; a = la; int a = * 2; PN
Write a program that takes two integer command-line arguments x and y and prints the Euclidean distance from the point (x, y) to the origin (0, 0).
Write a program that takes two integer command-line arguments a and b and prints a random integer between a andb, inclusive.
Write a program that prints the sum of two random integers between 1 and 6 (such as you might get when rolling dice).
Write a program that takes a double command-line argument t and prints the value of sin(2t) sin(3t).
Write a program that takes three double command-line arguments x0, v0, and t and prints the value of x0 + v0t − g t 2 / 2, where g is the constant 9.80665. (Note :This value is the displacement in
Write a program that takes two integer command-line arguments m and d and prints true if day d of month m is between 3/20 and 6/20, false otherwise.
Continuously compounded interest. Write a program that calculates and prints the amount of money you would have after t years if you invested P dollars at an annual interest rate r (compounded
Wind chill. Given the temperature T (in degrees Fahrenheit) and the wind speed v (in miles per hour), the National Weather Service defines the effective temperature(the wind chill) as follows:w =
Polar coordinates. Write a program that converts from Cartesian to polar coordinates. Your program should accept two double commandline arguments x and y and print the polar coordinates r and θ. Use
Gaussian random numbers. Write a program RandomGaussian that prints a random number r drawn from the Gaussian distribution. One way to do so is to use the Box–Muller formula r = sin(2 π v) (-2 ln
Order check. Write a program that takes three double command-line arguments x, y, and z and prints true if the values are strictly ascending or descending( x < y < z or x > y > z ), and false
Day of the week. Write a program that takes a date as input and prints the day of the week that date falls on. Your program should accept three int commandline arguments: m (month), d (day), and y
Uniform random numbers. Write a program that prints five uniform random numbers between 0 and 1, their average value, and their minimum and maximum values. Use Math.random(), Math.min(), and
Mercator projection. The Mercator projection is a conformal (anglepreserving)projection that maps latitude and longitude to rectangular coordinates(x, y). It is widely used—for example, in
Color conversion. Several different formats are used to represent color. For example, the primary format for LCD displays, digital cameras, and web pages, known as the RGB format, specifies the level
Great circle. Write a program GreatCircle that takes four double command-line arguments—x1, y1, x2, and y2—(the latitude and longitude, in degrees, of two points on the earth) and prints the
Three-sort. Write a program that takes three integer command-line arguments and prints them in ascending order. Use Math.min() and Math.max().
Dragon curves. Write a program to print the instructions for drawing the dragon curves of order 0 through 5. The instructions are strings of F, L, and R characters, where F means “draw line while
Write a program that takes three integer command-line arguments and prints equal if all three are equal, and not equal otherwise.
Write a more general and more robust version of Quadratic ( PROGRAM 1.2.3) that prints the roots of the polynomial ax2 + bx + c, prints an appropriate message if the discriminant is negative, and
What (if anything) is wrong with each of the following statements?a. if (a > b) then c = 0;b. if a > b { c = 0; }c. if (a > b) c = 0;d. if (a > b) c = 0 else b = 0;
Write a code fragment that prints true if the double variables x and y are both strictly between 0 and 1, and false otherwise.
Write a program RollLoadedDie that prints the result of rolling a loaded die such that the probability of getting a 1, 2, 3, 4, or 5 is 1/8 and the probability of getting a 6 is 3/8.
Improve your solution to EXERCISE 1.2.25 by adding code to check that the values of the command-line arguments fall within the ranges of validity of the formula, and by also adding code to print out
Suppose that i and j are both of type int. What is the value of j after each of the following statements is executed?a. for (i = 0, j = 0; i < 10; i++) j += i;b. for (i = 0, j = 1; i < 10; i++) j
Rewrite TenHellos to make a program Hellos that takes the number of lines to print as a command-line argument. You may assume that the argument is less than 1000. Use i % 10 and i % 100 to determine
Write a program that, using one for loop and one if statement, prints the integers from 1,000 to 2,000 with five integers per line. Use the % operation.
Write a program that takes an integer command-line argument n, uses Math.random() to print n uniform random values between 0 and 1, and then prints their average value.
Describe what happens when you try to print a ruler function (see the table on page 57) with a value of n that is too large, such as 100.
Write a program FunctionGrowth that prints a table of the values log n, n, n loge n, n2, n3, and 2 n for n = 16, 32, 64, ... , 2,048. Use tabs (\t characters) to align columns.
What are the values of m and n after executing the following code? int n = 123456789; int m= 0; while (n != 0) { } m (10 m) + (n % 10); n = n/ 10;
How many lines of output does the following code fragment produce?for (int i = 0; i < 999; i++);{ System.out.println("Hello"); }
Write a program that takes an integer command-line argument n and prints all the positive powers of 2 less than or equal to n. Make sure that your program works properly for all values of n.
Expand your solution to EXERCISE 1.2.24 to print a table giving the total amount of money you would have after t years for t = 0 to 25.EXERCISE 1.2.24Continuously compounded interest. Write a program
Unlike the harmonic numbers, the sum 1/12 + 1/22 + ... + 1/n2 does converge to a constant as n grows to infinity. (Indeed, the constant is 2/6, so this formula can be used to estimate the value of
Show that PROGRAM 1.3.6 implements Newton’s method for finding the square root of c. Use the fact that the slope of the tangent to a (differentiable)function f (x) at x = t is f (t) to find the
Using Newton’s method, develop a program that takes two integer command-line arguments n and k and prints the kth root of n
Modify Binary to get a program Kary that takes two integer commandline arguments i and k and converts i to base k. Assume that i is an integer in Java’s long data type and that k is an integer
Write a code fragment that puts the binary representation of a positive integer n into a String variable s.
Write a version of Gambler that uses two nested while loops or two nested for loops instead of a while loop inside a for loop.
Write a program GamblerPlot that traces a gambler’s ruin simulation by printing a line after each bet in which one asterisk corresponds to each dollar held by the gambler.
Modify Gambler to take an extra command-line argument that specifies the (fixed) probability that the gambler wins each bet. Use your program to try to learn how this probability affects the chance
Modify Gambler to take an extra command-line argument that specifies the number of bets the gambler is willing to make, so that there are three possible ways for the game to end: the gambler wins,
Modify Factors to print just one copy each of the prime divisors.
Run quick experiments to determine the impact of using the termination condition (factor
Write a program Checkerboard that takes an integer command-line argument n and uses a loop nested within a loop to print out a two-dimensional n-by-n checkerboard pattern with alternating spaces and
Write a program GreatestCommonDivisor that finds the greatest common divisor (gcd) of two integers using Euclid’s algorithm, which is an iterative computation based on the following observation: if
Showing 400 - 500
of 649
1
2
3
4
5
6
7