Assignment & Conditional Statements

  1. Declare a variable named numMinutes that holds a 32 bit whole number.
  2. Declare a variable named numSeconds that holds a 64 bit whole number
  3. Write code that creates a variable named ratio that has a value equivalent to the sine of 35 radians.
  4. Write code that creates a variable named length that has a value equivalent to the square root of 22.
  5. Write code that creates a variable name finished that holds the Boolean value true.
  1. Suppose two integers named maxAge and curAge are declared and have been initialized. Write a statement that creates a variable named process and using the ? operator, sets the value of process to true if curAge is not equal to maxAge, otherwise sets the value of process to false.
  2. Suppose a variable named average has been declared and initialized to some decimal value. Write a block of code that sets a Boolean variable named pass to true if average is greater than 65, otherwise sets pass to false.
  3. Suppose a variable named letterGrade has been declared and initialized to one of the characters A, B, C, D, or F. Write a block of code that sets a variable named points to a value dependent on the value of letterGrade according to the following table.

letterGrade points
A 5
B 4
C 3
D 2
F 0

  1. Suppose two variables named score1 and score2 hold decimal values. Write a block of code that uses a nested if statements to set the value of a third variable named result according to the following table.

result condition
score1 score1 is positive and score1 is greater than score2
score2 score1 is positive and score2 is greater or equal to score1
0 score1 is negative


© 2017, Eric. All rights reserved.