Skip to content

Instantly share code, notes, and snippets.

@SamuelSchwent
Created March 3, 2016 15:37
Show Gist options
  • Select an option

  • Save SamuelSchwent/8b2cb9e90e2a898fe8a9 to your computer and use it in GitHub Desktop.

Select an option

Save SamuelSchwent/8b2cb9e90e2a898fe8a9 to your computer and use it in GitHub Desktop.
Java - Search Example
package Challenge3;
public class Accounts {
int[] accountNumbers = {5658845, 4520125, 7895122, 8777541, 8451277, 1302850,
8080152, 4562555, 5552012, 5050552, 7825877, 1250255,
1005231, 6545231, 3852085, 7576651, 7881200, 4581002};
public boolean checkAccount(int number)
{
boolean isValid = false;
for (int x = 0; x <= accountNumbers.length - 1; x++)
{
if(number == accountNumbers[x])
isValid = true;
}
return isValid;
}
}
package Challenge3;
import java.util.Scanner;
public class AccountsDriver {
@SuppressWarnings("resource")
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
Accounts user = new Accounts();
boolean isValid = false;
int account;
System.out.println("Enter your Account Number");
account = keyboard.nextInt();
isValid = user.checkAccount(account);
if (isValid == true)
System.out.println("Account is VALID.");
else
System.out.println("Account is INVALID.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment