Spell Check Java Program Solution

Question

Ruya’s teacher gave her the assignment to practice the spelling of “RAINBOW”. Ruya’s mother helped her in
doing this by spelling each letter as Ruya wrote it in her notebook. If Ruya writes wrong spelling her mother should say “The spelling is wrong”

Sample Input 1:
Enter the first letter:R
Enter the second letter:A
Enter the third letter:I
Enter the fourth letter:N
Enter the fifth letter:B
Enter the sixth letter:O
Enter the seventh letter:W

Sample Output 1:

RAINBOW

Sample Input 2:
Enter the first letter:R
Enter the second letter:E
Enter the third letter:I
Enter the fourth letter:N
Enter the fifth letter:B
Enter the sixth letter:O
Enter the seventh letter:W

Sample Output 2:

The spelling is wrong

Code :-

import java.util.*;
class Character{
    public static void main(String[] args){
        char c1,c2,c3,c4,c5,c6,c7;
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter the first letter:");
        c1=sc.next().charAt(0);
        System.out.println("Enter the second letter:");
        c2=sc.next().charAt(0);
        System.out.println("Enter the third letter:");
        c3=sc.next().charAt(0);
        System.out.println("Enter the fourth letter:");
        c4=sc.next().charAt(0);
        System.out.println("Enter the fifth letter:");
        c5=sc.next().charAt(0);
        System.out.println("Enter the sixth letter:");
        c6=sc.next().charAt(0);
        System.out.println("Enter the seventh letter:");
        c7=sc.next().charAt(0);
        if(c1=='R' && c2=='A' && c3=='I' && c4=='N' && c5=='B' && c6=='O' && c7=='W'){
            System.out.println("RAINBOW");
        }
        else
            System.out.println("The spelling is wrong");
    }
}

Leave a Comment

Scroll to Top