1 / 2100%
import java.util.*;
public class Lab2
{
public static void main (String[] kushal)
{
//declare & initialize variables of different types
String firstName = "";
String lastName = "";
String fullName = "";
int nameLength = 0;
//create a Scanner object to get user input from keyboard
Scanner scan = new Scanner(System.in);
//user prompt to get user first name
System.out.println("Please enter first name: ");
firstName = scan.nextLine();
//user prompt to get user's last name
System.out.println("Please enter last name: ");
lastName = scan.nextLine();
// Convert fullName variable to upper case
fullName = (firstName + " " + lastName).toUpperCase();
// Find the length of fullName and store it in nameLength variable
nameLength = fullName.length();
// Print fullName in upper case
System.out.println("Full Name (in capitals): " + fullName);
// Print nameLength, it is number of characters in fullName variable,
including space
System.out.println("Length of full name: " + nameLength);
// Define two String variables, title1 and title2 using String
constructor
String title1 = new String("java");
String title2 = new String("java");
// Compare the two strings and print which one of the two ways works.
if (title1 == title2)
{
System.out.println("String comparison using '==' sign works");
}
else
{
System.out.println("String comparison using '==' sign does NOT
work");
}
if (title1.equals(title2))
{
System.out.println("String comparison using 'equals' method works");
}
else
{
package ASU;
/*-------------------------------------------------------------
// AUTHOR: Kushal Chachan
// ASU ID: 1217355724
// FOR: CSE 110 Lab #2
// SPECIFICATION: Using string operations
//-----------------------------------------------------------*/
System.out.println("String comparison using 'equals' method does NOT
work");
}
}
}
Powered by TCPDF (www.tcpdf.org)
Students also viewed