Results 1 to 2 of 2
Thread: Compare two strings
- 11-04-2010, 11:45 PM #1
Member
- Join Date
- Sep 2010
- Posts
- 20
- Rep Power
- 0
Compare two strings
Hello,
I wrote a little program that lets you compare the characters and display the number that are well or poorly placed, but I would like if there is a character in string1 that is not in string2, it is ignored. For example if string1: ABCD and string2 : ANBD, I want the program to tell me "2 well placed and 1 misplaced", N being ignored because it is not in the two chains. Here is what I have now:
ThanksJava Code:public class Main { static String chaine1 = "ABCD"; static String chaine2 = "BACD"; static int compteurBienPlaces; static int compteurMalPlaces; public static void main(String[] args) { for (int i = 0; i < chaine1.length(); i++) { char[] tableauChaine1 = chaine1.toCharArray(); char[] tableauChaine2 = chaine2.toCharArray(); if (tableauChaine1[i] == tableauChaine2[i]) { System.out.println("Le caractère " + tableauChaine1[i] + " est" + " bien placé"); compteurBienPlaces++; } else if (tableauChaine1[i] != tableauChaine2[i]) { System.out.println("Le caractère " + tableauChaine1[i] + " est" + " mal placé"); compteurMalPlaces++; } } System.out.println("Le nombre de caractères bien placés est de " + compteurBienPlaces + " et " + compteurMalPlaces + " sont mal " + "placés."); } }
- 11-04-2010, 11:57 PM #2
Member
- Join Date
- Oct 2010
- Posts
- 94
- Rep Power
- 0
Similar Threads
-
compare the remaining of Strings for equality
By Cylab in forum New To JavaReplies: 5Last Post: 08-19-2010, 02:42 PM -
compare the remaining of Strings for equality
By Cylab in forum Advanced JavaReplies: 6Last Post: 08-19-2010, 02:40 PM -
Compare between 2 Strings
By ChaosINC in forum New To JavaReplies: 3Last Post: 01-17-2010, 11:39 AM -
[SOLVED] Cant compare strings sent by client
By christuart in forum NetworkingReplies: 15Last Post: 09-01-2008, 03:24 AM -
how to compare two strings
By elizabeth in forum New To JavaReplies: 7Last Post: 08-06-2007, 03:57 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks