Comp Sci Java Program Helpers Come in Please

  • Thread starter Thread starter remaan
  • Start date Start date
  • Tags Tags
    Java Program
AI Thread Summary
The discussion focuses on writing a Java program to validate email addresses based on specific criteria, including the presence of a single '@', at least one '.' after it, and restrictions on character placement. Participants suggest using regular expressions for a more efficient solution, emphasizing that validation can be achieved in a single line of code. There is some confusion about the need for additional methods or classes in the implementation. The conversation highlights the importance of understanding Java's capabilities in handling string validation efficiently. Overall, the thread provides insights into best practices for email validation in Java programming.
remaan
Messages
132
Reaction score
0
Java Program Helpers Come in Please !

Homework Statement



I am writting a program which asks the user to enter his email adress, and then prints - according to five conditions - if his address is valid or not .

1. there should be exactly one @ in the address he enters.
2. there should be at least one '.' after the @ but not immdetly after it
3. '.' can not be the last character in the address.
4. After @ there should be never two '.' in a row.
5. The @ should not be the first one.





The Attempt at a Solution




The only thing I could think of is the last condition. I think I could that by using charAt(0)!= @

And, for the remaining conditions I thought about making a new method ?
using void so it does not return any thing, only checks

What do you think
 
Physics news on Phys.org


Thanks Thomas,

But I still have to create a new method, using void as will not return any thing
Right?
 


Please show us your coding attempt.
 


Look at the examples on the website I posted. It's basically one line of code, you don't need an extra method for that.
 


Ya, I looked at your website. But still am not sure how to do it " only one line of code "

What understod is : I have to make 2 classess in side the main class ?

However, still I can use methods to do it, right ?
 

Similar threads

Replies
7
Views
3K
Replies
1
Views
1K
Replies
12
Views
2K
Replies
2
Views
1K
Replies
7
Views
2K
Replies
1
Views
2K
Replies
1
Views
1K
Replies
1
Views
2K
Back
Top