Computer Science, asked by pragatirathore39, 6 hours ago

Write a program to input a character. If it is $ or _ then print VALID otherwise INVALID. [5]​

Answers

Answered by ItzMeSam35
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