Variable declarations

  1. Declare a variable named numMinutes that holds a 32 bit whole number and is initialized to the value of the integer read from the keyboard (use a print statement to ask the user to enter a whole number).
  2. Declare a variable named numSeconds that holds a 32 bit whole number and is initialized to 60 times the value stored in numMinutes.
  3. Write code that creates a variable name finished that holds the Boolean value true if the value in numSeconds is greater than or equal to 120 and holds false otherwise.  Print to the screen “Finished: ” followed by the value of the variable finished.
  4. Ask the user to enter an integer and store the integer in a variable named number.  Print to the screen “Is multiple of three: ” followed by true if the value in number is a multiple of three, and false otherwise.
  5. Declare two integers named maxAge and curAge and initialize them using values read from the keyboard (include print statements requesting integer values). Write a statement that creates a variable named overLimit that is set to true if the value of curAge is greater than the value of maxAge, and set to false otherwise.  Print to the screen, “Over the Limit:  ” followed by the value of the variable overLimit.
  6. Declare a variable named average and initialized it to the decimal value read from the keyboard (ask the user to enter the value). Write a block of code that sets a Boolean variable named passing to true if average is greater than 65, otherwise sets passing to false.  Print to the screen “Passed: ” followed by the value of the variable passing.
  7. Ask the user to enter a string from the keyboard and store the string in a variable named str.  Print to the screen “Length: ” followed by the length of str.
  8. Replace all of the instances of the character ‘a’ with the character ‘o’ and print the result to the screen.
  9. Declare a variable named idx and initialize it to the index of the first instance of the character ‘e’ in the string str.  Print to the screen “Index: ” followed by the value stored in idx.

© 2019 – 2020, Eric. All rights reserved.