Advertisement
joeldox

Initials Program

Dec 1st, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.09 KB | None | 0 0
  1. public class Initials
  2. {
  3.     public static void main(String[] args)
  4.     {
  5.         String name = "";
  6.         int lengthOfName = 0;
  7.         int name2 = 0;
  8.         char first = ' ';
  9.         char last = ' ';
  10.         int space = 0;
  11.         int lastNumber = 0;
  12.    
  13.    
  14.         System.out.println ("Please enter in your full name. (First and Last name ONLY.)");
  15.        
  16.         name = SavitchIn.readLine();
  17.        
  18.         lengthOfName = name.length();
  19.        
  20.         name2 = (lengthOfName - 1);
  21.        
  22.         System.out.println ("The length of your name is " + name2 + " characters.");
  23.        
  24.         if (name2 % 2 == 0)
  25.         {
  26.             System.out.println ("The length of your name is even.");
  27.         }
  28.         else
  29.         {
  30.             System.out.println ("The length of your name is odd.");
  31.         }
  32.         if (name2 % 3 == 0)
  33.         {
  34.             System.out.println ("The length of your name is divisible by 3");
  35.         }
  36.         else
  37.         {
  38.             System.out.println ("The length of your name is not divisble by 3");
  39.         }
  40.        
  41.         first = name.charAt(0);
  42.         space = name.indexOf(' ');
  43.         lastNumber = (space + 1);
  44.         last = name.charAt(lastNumber);
  45.         System.out.println ("Your first and last initials are " + first + "." + last + ".");
  46.        
  47.        
  48.        
  49.        
  50.        
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement