next up previous
Next: Input from a dialog Up: Unit 02 Previous: Input from the keyboard

Example: initials of a name read from input

import java.util.Scanner;

public class Initials {
  public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
    System.out.println("Insert first name");
    String fn = scanner.nextLine();
    System.out.println("Insert surname");
    String ln = scanner.nextLine();
    String ifn = fn.substring(0,1).toUpperCase();
    String iln = ln.substring(0,1).toUpperCase();
    System.out.println("Name: " + fn + " " + ln);
    System.out.println("Initials: " + ifn + iln);
  }
}


next up previous
Next: Input from a dialog Up: Unit 02 Previous: Input from the keyboard