Solutions to the Try It Out Exercises in Beginning Programming with Java For Dummies, 6th Edition
by Barry Burd

Chapter 8: Saving Time and Money: Reusing Existing Code

In this chapter:

What's in a name?

import java.util.Scanner;

public class MakeAName {

  public static void main(String[] args) {
    var keyboard = new Scanner(System.in);
    char c1, c2, c3;

    c1 = keyboard.findWithinHorizon(".", 0).charAt(0);
    c2 = keyboard.findWithinHorizon(".", 0).charAt(0);
    c3 = keyboard.findWithinHorizon(".", 0).charAt(0);

    System.out.print(Character.toUpperCase(c1));
    System.out.print(Character.toLowerCase(c2));
    System.out.print(Character.toLowerCase(c3));
    System.out.println();

    keyboard.close();
  }
}

Arrangements of letters

import java.util.Scanner;

public class Arrangements {

  public static void main(String[] args) {
    var keyboard = new Scanner(System.in);
    char c1, c2, c3;

    c1 = keyboard.findWithinHorizon(".", 0).charAt(0);
    c2 = keyboard.findWithinHorizon(".", 0).charAt(0);
    c3 = keyboard.findWithinHorizon(".", 0).charAt(0);

    System.out.print(c1);
    System.out.print(c2);
    System.out.println(c3);

    System.out.print(c1);
    System.out.print(c3);
    System.out.println(c2);

    System.out.print(c2);
    System.out.print(c1);
    System.out.println(c3);

    System.out.print(c2);
    System.out.print(c3);
    System.out.println(c1);

    System.out.print(c3);
    System.out.print(c1);
    System.out.println(c2);

    System.out.print(c3);
    System.out.print(c2);
    System.out.println(c1);

    keyboard.close();
  }
}

More character methods

Character.isDigit('a') = false

Character.isDigit('2') = true

Character.isLetter('a') = true

Character.isLetter('2') = false

Character.isLetterOrDigit('4') = true

Character.isLetterOrDigit('@') = false

Character.isLowerCase('b') = true

Character.isLowerCase('B') = false

Character.isLowerCase('7') = false

Character.isJavaIdentifierPart('x') = true

Character.isJavaIdentifierPart('7') = true

Character.isJavaIdentifierPart('-') = false

Character.isJavaIdentifierPart(' ') = false