modify it to create a class that contains a static method; the method takes a string as a parameter and returns a boolean value indicating whether the parameter string has repeated characters in it or not. That is, return true if there is at least one character which appear more than once in the string. The string should be input by the user public class Qns3 { public static void main(String args[]) { //input. Scanner Input = new Scanner(System.in); System.out.println ( "Enter the String to check for duplicate characters:"); String k = Input.next(); // repeated = true. boolean Repeat = false; for (int i = 0; i < k.length(); i++) for (int j = i + 1; j < k.length(); j++) if (k.charAt(i) == k.charAt(j)) Repeat=true; if (Repeat){ System.out.println("String have repeated characters" +k); } else System.out.println( "String have no repeated characters" +k); } }
modify it to create a class
that contains a static method; the method takes a string as a parameter and
returns a boolean value indicating whether the parameter string has repeated
characters in it or not. That is, return true if there is at least one character
which appear more than once in the string. The string should be input by the user
public class Qns3 {
public static void main(String args[]) {
//input.
Scanner Input = new Scanner(System.in);
System.out.println ( "Enter the String to check for duplicate characters:");
String k = Input.next();
// repeated = true.
boolean Repeat = false;
for (int i = 0; i < k.length(); i++)
for (int j = i + 1; j < k.length(); j++)
if (k.charAt(i) == k.charAt(j))
Repeat=true;
if (Repeat){
System.out.println("String have repeated characters" +k);
}
else
System.out.println( "String have no repeated characters" +k);
}
}
Step by step
Solved in 2 steps with 4 images