Q:

(Process a string) Write a program that prompts the user to enter a string and displays its length and its first character

0

(Process a string) Write a program that prompts the user to enter a string and displays its length and its first character.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

/*
(Process a string) Write a program that prompts the user to enter a string and displays
its length and its first character.
*/
import java.util.Scanner;

public class Exercise_04_20 {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);

		// Prompt the user to enter a string
		System.out.print("Enter a sting: ");
		String str = input.nextLine();

		// Display the string's length and its first character
		System.out.println(str + " has a length of " + str.length() +
			" and its first character is " + str.charAt(0));
	}
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now