I have a code that will take two user inputted strings, \"input\" and \"list\" T
ID: 3754506 • Letter: I
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 "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);
}
}
Explanation / Answer
import java.util.Scanner; public class Trim { public static boolean myTrim (String str , char ch) { int i; for( i = 0 ; iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.