Sorry for incomplete explanation..
I think you almost got it..
but I think you can do this in simple way..
1 @ case
==
you need to make a boolean function that return true if the username(String) contain '@'
private boolean checkforcase1(){
for(int i=0;i<username.length;i++){
//check the '@' character
//if it's there simply return true
}
return false;
}
if true, then you need to check
2. .com, .org etc case
===
first you have to find index where '.' is located, make a int function to get the location of '.'
if you got the location
now you need to get the string('.com','.org' or etc) from username, you can use one of String method, substring(int begin, int end)
assume begin is the '.' location and end is the length of username.
if the string is got, now you can compare with your predefine string array['.com','.org', etc] that you accepted..
if there is you can say that's a valid else invalid
the main flow diagram is like this
1. if case 1 is true than execute case 2 else return false and enter the invalid email address
2. if case 2 is return true you can print valid else invalid
There is more you can do with String (method), I suggested you to "try and error" which one you like...