Bonjour,
j'écris ce prg et l'obtient le fausse résultat,
je n'arrive pas trouver mon erreur,aidez moi svp
import java.io.*;
public class Cnt1
{
public static void main(String[]args)throws IOException
{
int times=0,count=0,x=0,no=0;
InputStreamReader ir=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(ir);
String s,w;
System.out.println("Enter the sentence:");
s=br.readLine();
System.out.println("Enter the word:");
w=br.readLine();
try
{
for(int i=0;i<s.length();i++)
{
if(w.charAt(0)==s.charAt(i))
{
for(int j=0;j<w.length();j++)
{
if(s.charAt(i)==w.charAt(j))
{
count=count+1;
}
if(count==w.length())
{
no=no+1;count=0;
}
else
{
System.out.println("word is present"+no+"times");
}
}}}}
catch(Exception e){}
if(no==0)
{}
{
System.out.println("word is not present");
}
}
}
e résultat est la suivante:
Enter the sentence:
je vais à paris
Enter the word:
paris
word is not present
Java:word is not present
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
× Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.