Write a java program that generates random string called str of 10 characters from the English alphabet (lower and upper case) and then find the longest sequence of characters from str that is also a substring in your First Name called matchStr.
The program should display:
1) The string str.
2) Your first name
3) The longest sequence matchStr.
Answers
Answer:
k g h j a df t r s we f a t s g
Explanation:
answer for points lol
A java program that generates random string called str of 10 characters from the English alphabet (lower and upper case) and then find the longest sequence of characters from str that is also a substring in your First Name called matchStr.
// Java program generate a random AlphaNumeric String
// using Math.random() method
public class RandomString {
static String getAlphaNumericString(int n)
{
// chose a Character random from this String
String AlphaNumericString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"+ "0123456789"+"abcdefghijklmnopqrstuvxyz";
// create StringBuffer size of AlphaNumericString
StringBuilder sb = new StringBuilder(n);
for (int i = 0; i < n; i++) {
// generate a random number between
// 0 to AlphaNumericString variable length
int index
= (int)(AlphaNumericString.length()
* Math.random());
// add Character one by one in end of sb
sb.append(AlphaNumericString
.charAt(index));
}
return sb.toString();
}
public static void main(String[] args)
{
int n = 10;
// Get and display the alphanumeric string
System.out.println(RandomString
.getAlphaNumericString(n));
}
}
#SPJ2