Tuesday 20 August 2013

How to solve this java puzzle?

How to solve this java puzzle?

Using the Java language, have the function PatternChaser(str) take str
which will be a string and return the longest pattern within the string.
A pattern for this challenge will be defined as: if at least 2 or more
adjacent characters within the string repeat at least twice. So for
example "aabecaa" contains the pattern aa, on the other hand "abbbaac"
doesn't contain any pattern.
Your program should return yes/no pattern/null. So if str were
"aabejiabkfabed" the output should be yes abe. If str were "123224" the
output should return no null. The string may either contain all characters
(a through z only), integers, or both. But the parameter will always be a
string type. The maximum length for the string being passed in will be 20
characters. If a string for example is "aa2bbbaacbbb" the pattern is "bbb"
and not "aa". You must always return the longest pattern possible
import java.util.*;
import java.io.*;
class Function {
String PatternChaser(String str) {
// code goes here
/* Note: In Java the return type of a function and the
parameter types being passed are defined, so this return
call must match the return type of the function.
You are free to modify the return type. */
return str;
}
}
class Main {
public static void main (String[] args) {
// keep this function call here
Scanner s = new Scanner(System.in);
Function c = new Function();
System.out.print(c.PatternChaser(s.nextLine()));
}
}

No comments:

Post a Comment