Question: Modify your Task #2 program to ignore the case sensitivity in checking whether the two lines of words are equal or not. The program will

Modify your Task #2 program to ignore the case sensitivity in checking whether the two lines of words are equal or not. The program will display Lines are equal, ignoring case or Lines are not equal, otherwise.

  1. Compile and run below program.

  2. Make sure to click on the Output Window to input the first number and the second number.

  3. Test the program. Take notes of the program with your observations and include in your comments.

  4. Submit your work.

The program that needs to be modified is:

import java.util.*; public class task2 { public static void main(String[] args) { Scanner sc=new Scanner(System.in); /*take input from user*/ System.out.print("Enter the first line : "); String line1=sc.nextLine(); System.out.print("Enter the Second line : "); String line2=sc.nextLine(); /*find the length of Lines*/ int l1 = line1.length(); int l2 = line2.length(); /*make one counter*/ int count=0; /*check length of lines are same or not if not than print not equal*/ if(l1==l2) { /*if equal than we check all words*/ for (int i = 0; i < l1; i++) { /*store line1 and line2 Character ascii value in varibles*/ int str1_ch = (int)line1.charAt(i); int str2_ch = (int)line2.charAt(i); /*check varibles value is same or not*/ if (str1_ch != str2_ch) { /*if not same than increment counter*/ count++; break; } } /*check count is 0 or not*/ if(count==0) { /*if zero than we print equal*/ System.out.println("Output : Lines are equal."); } else { /*else we print not equal*/ System.out.println("Output : Lines are not equal."); } } else { System.out.println("Output : Lines are not equal."); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!