Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Modify the program to include two-character .com names where the second characte

ID: 3674400 • Letter: M

Question

Modify the program to include two-character .com names where the second character can be a letter or a number, as in a2.com. Hint: Add a second loop, following the while (letter2 <= 'z') loop, to handle numbers.

import java.util.Scanner;

public class DomainNamePrinter {
public static void main (String [] args) {
Scanner scnr = new Scanner(System.in);
char letter1 = '?';
char letter2 = '?';

System.out.println("Two-letter domain names:");

letter1 = 'a';
while (letter1 <= 'z') {
letter2 = 'a';
while (letter2 <= 'z') {
System.out.println("" + letter1 +
"" + letter2 + ".com");
++letter2;
}
++letter1;
}

return;
}
}

Explanation / Answer

import java.util.Scanner;

class DomainNamePrinter {
   public static void main (String [] args) {
      Scanner scnr = new Scanner(System.in);
      char letter1 = '?';
      char letter2 = '?';
      int num = 0;

      System.out.println("Two-letter domain names:");

      letter1 = 'a';
      while (letter1 <= 'z') {
         letter2 = 'a';
         while (letter2 <= 'z') {
            System.out.println("" + letter1 +
                               "" + letter2 + ".com");
            ++letter2;
         }
         num =0;
         while(num <= 9 ){
             System.out.println("" + letter1 +
                               "" + num + ".com");
            ++num;
         }
         ++letter1;
      }

      return;
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote