Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Initials {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- String nameAndSurname, nameOnly;
- int c = 0, count = 0;
- System.out.println("Enter your full name please:");
- nameAndSurname = scan.nextLine();
- int space = nameAndSurname.indexOf(' ');
- for(int x = 0; x<=nameAndSurname.length()-1; x++) {
- c++;
- if(nameAndSurname.indexOf(x) == space) //if there is a space
- {
- count = c; //how many characters/letters was there before space
- System.out.println(count);
- }
- }
- nameOnly = nameAndSurname.substring(0, count);
- System.out.println("Your name is: " + nameOnly.toUpperCase() + " and it has " + count + " letters");
- scan.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement