0

Sample input 1: Enter Ist letter:J Enter 2nd letter:A Enter 3rd letter :V Enter 4th letter:A Sample output 1: JAVA

Sample input 2: Enter Ist letter:J Enter 2nd letter:A Enter 3rd letter :A Enter 4th letter:V Sample output 2: Wrong spelling

roshni
  • 25
  • 1
  • 7
  • Maybe starts here: https://stackoverflow.com/questions/3043306/reading-a-single-char-in-java . And then read about String her: https://docs.oracle.com/javase/7/docs/api/java/lang/String.html . And read a bit about the equals method here: https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html – Stefan Mar 14 '20 at 11:57
  • Already answered here: Ref: https://stackoverflow.com/questions/60660579/i-want-to-convert-series-of-characters-into-a-string-and-compare-with-another-st/60660634#60660634 – RRIL97 Mar 14 '20 at 12:00

1 Answers1

0

Try the following code.

public class Test {
    public static void main(String[] args) {
        String finalString = "";
        Scanner sc = new Scanner(System.in);
        for (int i = 1; i < 5; i++) {
            System.out.println("Enter " + i + "letter");
            String letter = sc.nextLine();
            finalString = finalString + letter;
        }

        if (!finalString.equals("JAVA")) {// you can test it with any string by replacing java
            System.out.println("Wrong spelling");
        } else {
            System.out.println(finalString);
        }
    }
}
SSK
  • 3,444
  • 6
  • 32
  • 59