Write a program to input a character. If it is $ or _ then print VALID otherwise INVALID. [5]
Answers
Answered by
2
import java.util.Scanner;
public class Character
{
public static void main (String args [])
{
Scanner sc=new Scanner (System.in);
System.out.print("Please enter a character : ");
char Character = sc.next().charAt(0);
if(Character == '$' || Character == '_')
{
System.out.println("VALID");
}
else
{
System.out.println("INVALID");
}
sc.close();
}
}
OUTPUT :-
Please enter a character : $
VALID
_________________________
Please enter a character : _
VALID
___________________________
Please enter a character : +
INVALID
Similar questions
Biology,
3 hours ago
Political Science,
3 hours ago
Science,
6 hours ago
Math,
8 months ago
Chemistry,
8 months ago