Wednesday 27 July 2016

Chapter 4 Exercise 20, Introduction to Java Programming, Tenth Edition Y. Daniel LiangY.

4.20 (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 ProgrammingEx4_20 {
 
 public static void main(String[] args) {
  Scanner input = new Scanner(System.in);
 
  System.out.print("Enter some string:");
  String s = input.nextLine();
  System.out.println("The string length is " + s.length());
  System.out.println("The first character is " + s.charAt(0));
 
 }
 
}

1 comment :