1. Engineering
  2. Computer Science
  3. java code about writing two methods public static string randomstringoneint...

Question: java code about writing two methods public static string randomstringoneint...

Question details
Java code about writing two methods:

public static String randomStringone(int length)
public static String randomStringtwo(int length)

This method should return a String of random lowercase letters with the given length by using for loops. To generate a random lowercase letter, use a local Random variable and the method nextInt() to generate a number between 97 and 122, then cast the result to a char. The method nextInt() can be found here: https://www.geeksforgeeks.org/java-util-random-nextint-java/   

  • In randomStringone(), you should use String concatenation like exampleString = exampleString + exampleChar;
  • In randomStringtwo(), use the methods provided by the StringBuilder class to build your String. You will create an instance of a StringBuilder and use it to manipulate the string in progress. You need to:
    • Append chars to a StringBuilder
    • Get the String from the StringBuilder (information about StringBuilder: https://docs.oracle.com/javase/10/docs/api/java/lang/StringBuilder.html)
Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution