write a program that takes a word from the keyboard and outputs whether it is an
ID: 3528302 • 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...........and can this be done on a switch statement using case instead of if? 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
// Here is the improvement of your code import java.util.Scanner; import java.lang.*; 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(); if (input.contains('@')) System.out.println("it's an email address."); else System.out.println("not an email address."); } }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.