1 / 5100%
Lab Topic: Strings
Working on "String" class and some of its methods.
Familiarization with basic data types.
Using the Scanner Class
Printing output
Find the correct way of string comparisons.
Getting familiar with Control Statements (If, else)
Problem Description
You will have to write a Java program that asks the user to enter two strings, firstname and
lastname, and concatenates the strings to make a full name. The program will use methods of class
“String” like length () and toUpperCase() on the full name and compare strings by equals() method
and if-else statements.
Sample Output
Below is an example of what your output should roughly look like when this lab is completed.
The red text are user inputs.
Note: When the program runs in submission system, you will NOT see any input like the red text
above. If you use to show prompts, your output might be on the same line. To avoid this print
issue, please use instead of to show the prompts. println print
Sample Run 1:
Please enter first name: magnus
Please enter last name: carlsen
Full name (in capitals): MAGNUS CARLSEN
Length of full name: 14
String comparison using "==" sign does NOT work
String comparison using "equals" method works
Sample Run 2:
Please enter first name: wesley
Please enter last name: so
Full name (in capitals): WESLEY SO
Length of full name: 9
String comparison using "==" sign does NOT work
String comparison using "equals" method works
CSE 110 - Lab 2
Step 1: Getting Started
Create a class called . Use the same setup for setting up your class and main method as you Lab2
did in previous lab. Be sure to name your file Lab2.java.
At the beginning of each programming assignment you must have a comment block with the
following information:
/*-------------------------------------------------------------
// AUTHOR: <Please put your name here>
// FILENAME: Lab2.java
// SPECIFICATION: <Describe your program>
// FOR: CSE 110 - Lab #2
// TIME SPENT: <Estimate time to complete this work>
//-----------------------------------------------------------*/
Your code should also have the class definition and one main function as follows:
1. // class name should the match file name
2. public class Lab2 {
3. // we a must have main method run to the program
4. public static void main(String[] args) {
Students also viewed