CSU Banner

CS 150, Spring 2018

Programming Assignment - P4

Introduction to Strings and String Methods

Due - March 6th, 2018 at 6:00pm

Late - March 7th, 2018 at 8:00am

Objectives of this Assignment

  1. To write a program that uses the String class of Java,
  2. to declare a String object and initialize it by user input, and
  3. to learn how to implement a few basic String methods.


Create a Java program called P4 with a class named P4, which after created should contain a file named P4.java in the src folder. An example of the code is shown below. All of the Java code you write should be contained in the main method. For this assignment, you must follow the directions below exactly:

Program Structure

// P4 Assignment 
// Author: Russ Wakefield
// Date:   9/24/2017
// Class:  CS150
// Email:  waker@colostate.edu

import java.util.Scanner;

public class P4 {

    public static void main(String[] args) {

        // Declare String object.

        // Instantiate Scanner (declare and initialize).

        // Prompt user and initialize testString.
        // Print output to console.

        // Close scanner
    } // end main
} // end class P4

Sample Output

Your program should print eight lines. This includes the first, where the user enters the value for testString. User input is shown in blue.

Program String: Java is fun! 
1: Java is fun!
2: 12
3: 1
4: v
6: a is fun!
7: va i


Grading Criteria

Submit P4.java to Checkin.

CS Banner
CS Building