Spring Semester 2002 |
Questions:
dm = m * ((Math.sqrt(1 + v / c) / Math.sqrt(1 - v / c)) - 1); volume = Math.PI * r * r * h; volume = 4 * Math.PI * Math.pow(r, 3) / 3;
x1 = (-b - Math.sqrt(b * b - 4 * a * c)) / 2 * a; x2 = (-b + Math.sqrt(b * b - 4 * a * c)) / 2 * a;
n
be an integer and x
a floating-point number. Explain the difference between
andn = (int)x;
For what values ofn = (int)Math.round(x);
x
do they give the same result?
For what values of x
do they give different results?
What happens if x
is negative?
public class WarmUpSix { public static void main(String[] args) { System.out.print("This program adds two numbers.), x = 5; int y = 3.5; System.out.print("The sum of " + x + " and " + y " is: "); System.out.println(x + y) } }
public class WarmUpSeven { public static void main(String[] args) { ConsoleReader console = new ConsoleReader(System.in); int total = 1; System.out.println("Please enter a number:"); int x1 = Integer.parseInt(console.readLine()); total = total + x1; System.out.println("Please enter another number:"); int x2 = Integer.parseInt(console.readLine()); total = total + x1; double average = total / 2; System.out.println("The average of two numbers is " + average); } }
2
, 2.0
, "2"
, and "2.0"
.
andx = 2; y = x + x;
s = "2"; t = s + s;
x
is an int
and
s
is a String
)
Integer.parseInt("" + x)
is the same as x
"" + Integer.parseInt(s)
is the same as s
s.substring(0, s.length())
is the same as s
n
is 23456
, how do you find out
2
and 6
? Do not convert the number to a string.
Hint: %
, Math.log
final
variable? Can you define a final
variable without supplying its value?
What are the values of the following expressions?double x = 2.5; double y = -1.5; int m = 18; int n = 4; String s = "Hello"; String t = "World";
x + n * y - (x + n) * y
m / n + m % n
5 * x - n / 5
Math.sqrt(Math.sqrt(n))
(int)Math.round(x)
(int)Math.round(x) + (int)Math.round(y)
s + t
s + n
1 - (1 - (1 - (1 - (1 - n))))
s.substring(1, 3)
s.length() + t.length()
Some advice, at the end of this document: