Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Initials
- {
- public static void main(String[] args)
- {
- String name = "";
- int lengthOfName = 0;
- int name2 = 0;
- char first = ' ';
- char last = ' ';
- int space = 0;
- int lastNumber = 0;
- System.out.println ("Please enter in your full name. (First and Last name ONLY.)");
- name = SavitchIn.readLine();
- lengthOfName = name.length();
- name2 = (lengthOfName - 1);
- System.out.println ("The length of your name is " + name2 + " characters.");
- if (name2 % 2 == 0)
- {
- System.out.println ("The length of your name is even.");
- }
- else
- {
- System.out.println ("The length of your name is odd.");
- }
- if (name2 % 3 == 0)
- {
- System.out.println ("The length of your name is divisible by 3");
- }
- else
- {
- System.out.println ("The length of your name is not divisble by 3");
- }
- first = name.charAt(0);
- space = name.indexOf(' ');
- lastNumber = (space + 1);
- last = name.charAt(lastNumber);
- System.out.println ("Your first and last initials are " + first + "." + last + ".");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement