Question: I have a code that will take two user inputted strings, input and list The code then returns another string that has the words from

I have a code that will take two user inputted strings, "input" and "list"

The code then returns another string that has the words from "input" but any repeating letters included in "list" are removed.

for example:

input: blackberries

list: berries

output: erries

Right now, this java code is case sensitive. What can I do to make it case insensitive? Meaning, if input contains "B" and list contains "b" output will remove the letter b even though one is uppercase and one is lowercase.

The code:

import java.util.Scanner;

public class Trim

{

public static boolean myTrim (String str , char ch)

{

int i;

for( i = 0 ; i < str.length() ; i++ )

{

if( str.charAt(i) == ch )

return true;

}

return false;

}

public static void main(String[] args)

{

Scanner x = new Scanner(System.in);

System.out.print("Enter first string : ");

String input = x.nextLine();

System.out.print("Enter second string : ");

String list = x.nextLine();

String ans = " ";

int i;

for( i = 0 ; i < input.length() ; i++ )

{

if( myTrim( list , input.charAt(i) ) == false )

ans += String.valueOf( input.charAt(i) );

}

System.out.println("Final String: " + ans);

}

}

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!