Practice Questions (Code Writing)

Loops

Table of contents
  1. Easy CodeCheck Questions
  2. Medium CodeCheck Questions

CodeCheck Questions

  1. Complete the program below so that it prompts for a string of characters, prints out the last character of the string, followed by the first character of the string, followed the three middle characters of the string. You may assume that all the inputs string are of odd length and have at least five characters.
    For example, if the user enters the string aforesaid, you should print
    dares
    Solve it here
  2. Complete the program below so that it prompts for a string and an integer n, that is no larger than the length of the string, and then prints out the last n characters of that string. For example, given the input string, “Hello, World!” along with the integer 5, the output should be
    orld!
    Solve it here
  3. Write a method getLastFirst whose parameter is a string containing a name such as “Harry Smith” and that returns a string with the last name followed by a comma and the first name, like this: “Smith, Harry”
    Solve it here
  4. Complete the program below, named Initials.java, to read in a first name, a middle name, and a last name, and then print out the three initials as a single string. For example, if the three input names are James, Paul, and Jones, then the output should be JPJ.
    Solve it here
  5. Complete the initials method in the class below. For example, the call initials(“Harry”, “Joseph”, “Hacker”) should return the string “HJH”.
    Solve it here

Back to Top

Medium CodeCheck Questions

Back to Top