-2

System.out.println("Ange följande:");

    System.out.print("Name: ");
    String firstName = keyboard.nextLine();
    firstName = firstName.substring(0,1).toUpperCase() + firstName.substring(1).toLowerCase();

    while (firstName.equals("")) {
        System.out.println("Name line can't be empty!!");
        System.out.print("Name: ");
        firstName = keyboard.nextLine();
    }
Marcus
  • 3
  • 2

2 Answers2

0
    System.out.print("Name: ");
    String firstName = keyboard.nextLine();

    while (firstName.trim().equals("")) {
        System.out.println("Name line can't be empty!!");
        System.out.print("Name: ");
        firstName = keyboard.nextLine();
    }
    firstName = firstName.substring(0, 1).toUpperCase() + firstName.substring(1).toLowerCase();
    System.out.println(firstName);

move the line where you make the first letter upper case after the while and also use trim() in your while statement to make sure there are not just space entered

XtremeBaumer
  • 6,275
  • 3
  • 19
  • 65
0

You can put any string instead of Abcd in the below code -

public static void main(String[] args) throws ParseException {
    String check = "Abcd";
    if(check.isEmpty()){
        System.out.println("can't be empty...");
        System.exit(0);
    }
    char charAt = check.charAt(0);
    if(Character.isUpperCase(charAt)){
        //do stuff condition satisfied
    }
}
ketan
  • 2,732
  • 11
  • 34
  • 80