Try the fastest way to create flashcards

Related questions with answers

Question

Use the methods in the following program to print 100 uppercase letters and then 100 single digits, printing ten per line.

1   public class RandomCharacter {
2       /** Generate a random character between ch1 and ch2 */
3       public static char getRandomCharacter(char ch1, char ch2) {
4           return (char)(ch1 + Math.random() * (ch2 - ch1 + 1));
5       }
6
7       /** Generate a random lowercase letter */
8       public static char getRandomLowerCaseLetter() {
9           return getRandomCharacter('a', 'z');
10      }
11
12      /** Generate a random uppercase letter */
13      public static char getRandomUpperCaseLetter() {
14          return getRandomCharacter('A', 'Z');
15      }
16
17      /** Generate a random digit character */
18      public static char getRandomDigitCharacter() {
19          return getRandomCharacter('0', '9');
20      }
21
22      /** Generate a random character */
23      public static char getRandomCharacter() {
24          return getRandomCharacter('\u0000', '\uFFFF');
25      }
26  }

Solution

Verified
Answered 2 years ago
Answered 2 years ago
Step 1
1 of 4

To print 100100 random uppercase letters and 100100 random digits we will need to use 2 methods. getRandomCharacter method will be used to generate characters. main method will call getRandomCharacter method and print results.

public class Main {
  public static void main(String[] args) {}

  public static char getRandomCharacter(char ch1, char ch2) {}
} 

Create a free account to view solutions

Create a free account to view solutions

Recommended textbook solutions

Intro to Java Programming, Comprehensive Version 10th Edition by Y. Daniel Liang

Intro to Java Programming, Comprehensive Version

10th EditionISBN: 9780133761313Y. Daniel Liang
1,628 solutions
Fundamentals of Database Systems 7th Edition by Ramez Elmasri, Shamkant B. Navathe

Fundamentals of Database Systems

7th EditionISBN: 9780133970777Ramez Elmasri, Shamkant B. Navathe
948 solutions
Introduction to Algorithms 3rd Edition by Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen

Introduction to Algorithms

3rd EditionISBN: 9780262033848Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen
872 solutions
Introduction to Algorithms 4th Edition by Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen

Introduction to Algorithms

4th EditionISBN: 9780262046305Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen
945 solutions

More related questions

1/4

1/7