Hi I'm trying to break down a given email address by name and domain and all is well except for the "." in the domain piece. The email format I am looking at is abc.def@hijk.com. Looks like the selector to print the first "." is carrying to the second one. Can anyoe help me with a simple way around this? I am new to Java and a complicated solution will not be very helpful to me. thanks in advance
Tony
import java.util.Scanner;
public class emailBreakdown
{
public static void main(String [] args)
{
System.out.println("Enter the email address to be parsed");
Scanner email = new Scanner(System.in);
String s1 = email.nextLine();
int length= s1.length();
for (int i =0; i<s1.length(); i++)
{
char result =s1.charAt(i);
System.out.print(result);
}
System.out.println();
System.out.print("Name :");
for (int i=0; i< s1.length(); i++)
{
if (s1.charAt(i)=='.')
System.out.print(" ");
else if (s1.charAt(i) == '@')
{
System.out.println();
System.out.print("Domain :");
}
else if (s1.charAt(i)=='.')
{
System.out.print(".");
}
else
{
System.out.print(s1.charAt(i));
}
}
}
}
Tony
import java.util.Scanner;
public class emailBreakdown
{
public static void main(String [] args)
{
System.out.println("Enter the email address to be parsed");
Scanner email = new Scanner(System.in);
String s1 = email.nextLine();
int length= s1.length();
for (int i =0; i<s1.length(); i++)
{
char result =s1.charAt(i);
System.out.print(result);
}
System.out.println();
System.out.print("Name :");
for (int i=0; i< s1.length(); i++)
{
if (s1.charAt(i)=='.')
System.out.print(" ");
else if (s1.charAt(i) == '@')
{
System.out.println();
System.out.print("Domain :");
}
else if (s1.charAt(i)=='.')
{
System.out.print(".");
}
else
{
System.out.print(s1.charAt(i));
}
}
}
}