Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8871591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:01:33+00:00 2026-06-14T18:01:33+00:00

I am trying to make a code that can detect mistakes in the user

  • 0

I am trying to make a code that can detect mistakes in the user input with respect to String array stored in program.

Lets say Program contains “The quick brown fox jumps over the lazy dog”

if the user enters “The quick brown is name over Jumps the lazy”

The program tells the user that you have made 5 Mistakes. But my code is not working correctly for the above mentioned user input. What is my code lacking to detect such mistakes. Here is the code:

public void checkTextCompleted()
{
    String input= text.getText();
    int temp=array[0],mistakes=0;

    if(input.length()==data.length()) {
        text.setEditable(false);
        text.setFocusable(false);

        for(int j=0;j<dataWords;j++) {
            int x = input.indexOf(data.substring(array[j]-temp, array[j]-1));

            System.out.println(x);
            if(x != -1) {
                String subs = input.substring(x, input.length());

                if(data.contains(subs)) {
                    break;
                } else {
                    mistakes++;
                    if(j!=0)
                        temp=array[j-1];
                    else
                        temp=array[j];
                }
            }
            else
                mistakes++;
        }
        JOptionPane.showMessageDialog(null,"You have made "+mistakes+" mistakes" , "Typing Test Completed", JOptionPane.OK_OPTION);
    }
}

The array[] contains the positions at which the space is detected in Program builtin String(data) and dataWords contains the number of words in program builtin String(data). User input is stored in “input”

What is my code lacking to detect the above mentioned problem?

Note:
if one word is wrong and the remaining string after it is correct, mistake will be 1 other wise, next mistake will be detected on the same principal.

enter image description here

Regards

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T18:01:34+00:00Added an answer on June 14, 2026 at 6:01 pm

    Cant you shrink your code by this simple logic ?

    String[] expectedSentenceA = "The quick brown fox jumps over the lazy dog".split(" ");
    String[] inputStringA = inputString.split(" ");
    int diff=  expectedSentenceA.length-inputStringA.length;
    if(diff>0) {
        System.out.println("You have missed " + diff + " word(s)..!!!");
    } else if (diff < 0) {
        System.out.println("Found " + diff + " excess word(s)..!!!");
    }else {
       ArrayList<String> mistakeWords= new ArrayList();
       for(int i=0;i<expectedSentenceA.length;i++) {
        if(!expectedSentenceA[i].equals(inputStringA[i])){
            mistakeWords.add(inputStringA[i]);
        }
       }
       JOptionPane.showMessageDialog(null,"Total Mistakes ["+mistakeWords.size()+"] are " + mistakeWords);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to make a frame from code so that I can apply
In the code below, I'm trying to make it so that, if a user
I'm trying to make a code that will show two different images depending on
I'm trying to make a genric code to serialize and deserialize any object that
I'm trying to make a click at desktop through code, so I did that:
I'm trying to make a CSS code that changes the cursor to a picture
I'm trying to make a code that automatically counts the members in a particular
So I'm trying to make a window that can have a horizontal or vertical
I an trying to create a program that will detect a face in a
I'm trying to make this code generic: public final Object unwrap(Class arg0) { throw

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.