Assign the size of userInput to stringSize Ex if userInput is Hello output is

Assign the size of userinput to stringsize ex if

This preview shows page 5 out of 5 pages.

Assign the size of userInput to stringSize. Ex: if userInput is "Hello", output is: Size of userInput: 5 import java.util.Scanner; public class StringSize { public static void main ( String [] args) { Scanner scnr = new Scanner( System .in); String userInput; int stringSize; userInput = scnr.nextLine(); stringSize = userInput.length(); System .out.println( "Size of userInput: " + stringSize); return ; } } All tests passed CHALLENGE ACTIVITY 3.10.2: Looking for characters. Write an expression to detect that the first character of userInput matches firstLetter. import java.util.Scanner; public class CharMatching { public static void main ( String [] args) { Scanner scnr = new Scanner( System .in); String userInput; char firstLetter; userInput = scnr.nextLine(); firstLetter = scnr.nextLine().charAt( 0 ); if (firstLetter == userInput.charAt( 0 )) { System .out.println( "Found match: " + firstLetter); } else { System .out.println( "No match: " + firstLetter); } return ; } } All tests passed
Image of page 5

You've reached the end of your free preview.

Want to read all 5 pages?

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture