by CodeChum Admin
Can you identify if Cody's name is spelled right? If so, then make a program that accepts four one-letter strings separated by space and print "Correct" if the inputted strings, combined in order, spell the name Cody correctly. If not, print "Wrong". It doesn't matter if it's in uppercase or lowercase, as long as it's spelled correctly, it's considered correct.
Now, will you take on this task?
Input
A line containing four one-letter strings separated by a space.
c·O·D·y
Output
A line containing a string.
Correct
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the name: ");
String name = sc.nextLine();
sc.close();
if(name.replaceAll(" ", "").equalsIgnoreCase("cody")) {
System.out.println("Correct");
} else {
System.out.println("Wrong");
}
}
}
Comments
Leave a comment