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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started