I am trying to write java code (method) to validate a user id. which prompts user to input an id. If user begins with digit 1 - this will be displayed as invalid!!! I would be grateful for any help! Thanks
public static void main(String[] args) {
//creating an array of 10
int[] num = new int[10];
//asking user to enter a number
Scanner kb = new Scanner(System.in);
System.out.println("Enter and id number : ");
num = kb.nextInt();
//calling method
GetValidInteger(num);
}
//method
static void GetValidInteger(int[] num) {
//looping through the array to get the numbers
for (int i = 0; i < num.length; i++) {
//if num at index 0 is 1 print out invalid
if (num[0] == 1) {
System.out.println("The number you have entered :" + num + " starts with 1 and is invalid");
}
//else print out valid
else {
System.out.println("The number you have entered :" + num + " is valid");
}
}
}
I am getting an error: int cannot be converted into int[]!
at this line: num = kb.nextInt();