ok, so i'm enrolled my first programming course and we finally have to create an actual program. what i'm trying to do in my program is to create a while loop that checks if a variable is not of string type. but like i said, i'm very new at this and i don't really know what the correct syntax would be to do this.

thanks for any help

import java.util.Scanner;
public class Payroll {
	public static void main(String[] args) {

	Scanner input = new Scanner(System.in);
	int x;
	x = 1;
	System.out.println("To finish entering employee information, enter 'done' into the first name field.");
	System.out.println("Enter employee " + x + "'s first name.");
	String firstname = input.next();
	while(firstname != " ") {
		System.out.print("you're dumb, enter something new");
		firstname = input.next();

	}
	}
}

what i want the while loop to do is basically re-ask the question if someone inputs numbers or symbols instead of an actual name

Don't know if it is the best option, but I would probably write a function to check each character from the user input. So traverse through the user input and check that conditions such as >= a, <=z, are satisfied or whatever you requirements are.

first of all I suggest you learn what scanner class is capable of. Not because you are doing something wrong, but there is a lot of different functions that you can use in that class. here is a link to java specifications. and here is a link to scanner class. every time you use a class check the specifications. there is examples in there. and it tells everything you can do with it.

String.matches("[a-zA-Z]*");
Will return true for a blank field or a string consisting of nothing but letters. You can tailor that pattern to allow spaces, certain punctuation, fail a blank entry, etc. to suit your needs.

thanks for the tips guys, i'll try and use what you told me and learn more

This article has been dead for over six months. Start a new discussion instead.