Advertisement
Guest User

java q4

a guest
Oct 23rd, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.99 KB | None | 0 0
  1. package question;
  2. import java.util.*;
  3. public class Question {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner input = new Scanner(System.in);
  7.         //input name
  8.         String name = new String();
  9.         System.out.println("Please input your full name");
  10.         name = input.nextLine();
  11.         //input student number
  12.         String number = new String();
  13.         System.out.println("Please input your student number");
  14.         number = input.nextLine();
  15.        
  16.         //output first name initial
  17.         String x = new String(name.toUpperCase());
  18.        
  19.         char first = name.charAt(0);
  20.         System.out.print(first);
  21.        
  22.         //output last name initial
  23.         for (int y = 1; y < x.length(); y++)
  24.             {
  25.             char last = x.charAt(y);
  26.  
  27.             if (last == ' ')
  28.             {
  29.             System.out.print(x.charAt(y + 1)+" ");
  30.             }
  31.         }
  32.         //output student number
  33.         System.out.println(number.substring(6, 9));
  34.     }
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement