Java code that will accept the language formed by the following two characters?
Greetings, I asked an identical question in advance of but knew it had not been worded actually so could possibly someone assistance me with all the following make sure you…
Write Java code that will accept the actual language formed from the following a couple of characters I and V.You may perhaps assume the particular input is already stored within a String variable called inString and is comprising upper case letters.The program ought to accept and rejects feedback strings while follows:
Admit:I, II, VII, Refrain from:XL, XXXVIII, LX, XCIV.
Thanks
public course Main
arrest static void main(String args)
Stringed inString=”XXXVIII”;
char charac= inString.toCharArray();
boolean isTrue=true;
for(int i=0; i<charac.size; i++)
if(! (characi == ‘I’ characi == ‘V’))
isTrue=false;
if(isTrue)
Procedure.out.println(“accepted”);
else
Procedure.out.println(“rejected”);
Anticipation this facilitates!
Why not merely reject every string that includes a character that may be not a great I and also a V You can use a typical expression to complete it, a built-in Java method that will tell you in case a character exists inside string, or write your special! The program masters the string one character at the same time, if them finds a characters that isn’t an I or some sort of V after that the string is quickly rejected.
Leave a Reply
You must be logged in to post a comment.