Solutions to the Try It Out Exercises in Beginning Programming with Java For Dummies, 5th 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;

class MakeAName {

  public static void main(String args[]) {
    Scanner 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;

class Arrangements {

  public static void main(String args[]) {
    Scanner 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

|  Welcome to JShell -- Version 9-ea
|  For an introduction type: /help intro

jshell> Character.isDigit('a')
$1 ==> false

jshell> Character.isDigit('2')
$2 ==> true

jshell> Character.isLetter('a')
$3 ==> true

jshell> Character.isLetter('2')
$4 ==> false

jshell> Character.isLetterOrDigit('4')
$5 ==> true

jshell> Character.isLetterOrDigit('@')
$6 ==> false

jshell> Character.isLowerCase('b')
$7 ==> true

jshell> Character.isLowerCase('B')
$8 ==> false

jshell> Character.isLowerCase('7')
$9 ==> false

jshell> Character.isJavaIdentifierPart('x')
$10 ==> true

jshell> Character.isJavaIdentifierPart('7')
$11 ==> true

jshell> Character.isJavaIdentifierPart('-')
$12 ==> false

jshell> Character.isJavaIdentifierPart(' ')
$13 ==> false

jshell> /exit
|  Goodbye