Using your solution to Pen 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 appears more than once in the string. The string should be input by user public class Pen { 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); } } //Ends
Using your solution to Pen
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 appears more than once in the string. The string should be input by user
public class Pen {
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);
}
}
//Ends

Step by step
Solved in 4 steps with 3 images









