Jump to content
  • Advertisement
Sign in to follow this  

java logic error..

This topic is 3736 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I realy cant get why this does not work.. been trying for two hours to get it working... its supposed to check if any char is repeated in the string.. It works if I type inn 'abc def' , but eg 'abc def gh' does not work..
import java.util.Scanner;

class repchar
	public static void main(String args[])
		Scanner input = new Scanner(System.in);
		System.out.println("Pleas enter a string.");
		String str = input.nextLine();
		int sLength = str.length();
		boolean match = false;
		int i = 0;
		while(!match && i < sLength)
			char chkChar = str.charAt(i);
			int j = i + 1;
			while(!match && j < sLength)
				if(str.charAt(j) == chkChar)
					match = true;

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!