I need know how to Write a java program called character length that prompts the user to enter a string and displays:x is the first character.) The length of the string is: xxxxx The strings first character is: x (where xxxxx is the length of the string and x is the first character.)
//CharacterLength.java import java.util.Scanner; public class CharacterLength { public static void main(String[] args) { // Creating scanner object Scanner scan = new Scanner(System.in); // Printing text to console System.out.print("Enter a string: "); // Reading string from user String s = scan.nextLine(); // Printing length of string System.out.println("The length of the string is: "+s.length()); // Printing first character of string System.out.println("The strings first character is: "+s.charAt(0)); } }
Get Answers For Free
Most questions answered within 1 hours.