Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

write a program that takes a word from the keyboard and outputs whether it is an

ID: 3528331 • Letter: W

Question

write a program that takes a word from the keyboard and outputs whether it is an email address based on the presence of the @ character.......here is what I have but unfortunately we are told to use the "indexOf" import java.util.Scanner; public class Charat { public static void main (String [] args) { Scanner scan = new Scanner(System.in); System.out.println("your word is "); string input = scan.nextLine(); char a = '@'; if (input.equals('@')) System.out.println("it's an email address."); else System.out.println("not an email ."); } }

Explanation / Answer

/** indexOf() will give the index of given char in the particular string**/ /** and if character is not present it will reutn -1 **/ /** so your code with indexOf is below******/ import java.util.Scanner; public class Charat { public static void main (String [] args) { Scanner scan = new Scanner(System.in); System.out.println("your word is "); String input = scan.nextLine(); char a = '@'; if (input.indexOf(a)==-1) System.out.println("it's not an email address."); else System.out.println("It's an email address."); } }