Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a complete Java program in a source file to be named Assignment3.java. The

ID: 3792450 • Letter: W

Question

Write a complete Java program in a source file to be named Assignment3.java. The program should ask a user to enter two strings. First, the program prompts: Please enter a string. The program should read in the string a user enters, and prompts: Please enter another string. The program reads in the string and performs the following: checks if each string's length is odd or even. checks if two strings are same or different. checks which string is lexically larger, or they are same. prints out the first character (index 0) of each string prints out a new string consisting of the first string concatenated (appended) with the second string. prints out two strings using upper case letters. Here is the output your program should produce when the user enters the string shown in bold: Sample Output: (the user enters the string shown in bold) Please enter a string. Apple Please enter another string. Orange The first string's length is odd. The second string's length is even. The two strings are different. The second string is lexically larger. The first character of the first string is A The first character of the second string is O The concatenation of two strings is "AppleOrange" The first string using upper case letters: APPLE The second string using upper case letters: ORANGE

Explanation / Answer

Assignment2.java

import java.util.Scanner;

public class Assignment2 {

   public static void main(String[] args) {
      
       //Declaring variables
       String str1,str2;
      
       //Scanner object is used to get the inputs entered by the user
               Scanner sc=new Scanner(System.in);
              
               //Getting the first string entered by the user
               System.out.println("Please Enter a String :");
str1=sc.next();
  
               //Getting the second string entered by the user
               System.out.println("Please Enter another String :");
str2=sc.next();
  
//getting the length of the first string
int str1len=str1.length();
  
//getting the length of the second string
int str2len=str2.length();
  
//Checking whether the first string is even or odd
if(str1len%2==0)
   System.out.println("The first string length is even");
else
   System.out.println("The first string length is odd");

//Checking whether the second string is even or odd
if(str2len%2==0)
   System.out.println("The second string length is even");
else
   System.out.println("The second string length is odd");
  
//Checking whether the two strings are equal or not
if(str1.equals(str2))
   System.out.println("The two strings are same");
else
   System.out.println("The two strings are different");
  
//Comparing the two strings lexically
if(str1.compareTo(str2)==0)
   System.out.println("The two strings are lexically same");
else if(str1.compareTo(str2)>0)
   System.out.println("The first string is lexically larger");
else if(str1.compareTo(str2)<0)
   System.out.println("The second string is lexically larger");
  
//getting the first character of the first string
System.out.println("The first charcater of the first string is "+str1.charAt(0));
  
//getting the first character of the second string
System.out.println("The first charcater of the second string is "+str2.charAt(0));
  
//concatination the first string with the second string
System.out.println("The concatination of two string is "+(str1+str2));
  
//Converting the first string to upper case
System.out.println("The First string using upper case letters :"+str1.toUpperCase());

//Converting the second string to upper case
System.out.println("The Second string using upper case letters :"+str2.toUpperCase());
   }

}

______________________

output:

Please Enter a String :
Apple
Please Enter another String :
Orange
The first string length is odd
The second string length is even
The two strings are different
The second string is lexically larger
The first charcater of the first string is A
The first charcater of the second string is O
The concatination of two string is AppleOrange
The First string using upper case letters :APPLE
The Second string using upper case letters :ORANGE

__________Thank You

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote