Chapter 2 Notes
System.out.println(secondVerse);return;}}2.13.1: String with digit.Set hasDigit to true if the 3-character passCode contains a digit. public class CheckingPasscodes {public static void main (String [] args) {boolean hasDigit = false;String passCode = “”;int valid = 0;passCode = “abc”;if (Character.isDigit(passCode.charAt())) { hasDigit = true;} if (Character.isDigit(passCode.charAt(1))) { hasDigit = true;} if (Character.isDigit(passCode.charAt(2))) { hasDigit = true; }
if (hasDigit) {System.out.println(“Has a digit.”);}else {System.out.println(“Has no digit.”);}return;}}2.13.2: Whitespace replace.Write code to print the location of any space in the 2-character string passCode. Each space detected should print a separate statement followed by a newline. Sample output for the given program:Space at 1import java.util.Scanner;public class FindSpaces {public static void main (String [] args) {String passCode = “”;passCode = “A “;if (Character.isWhitespace(passCode.charAt(0)) && Character.isWhitespace(passCode.charAt(1))) {System.out.println(“Space at 0”);System.out.println(“Space at 1”);} else if (Character.isWhitespace(passCode.charAt(0))) { System.out.println(“Space at 0”);} else if (Character.isWhitespace(passCode.charAt(1))) {
System.out.println(“Space at 1”);} else {}return;}}