السلام عليكم ورحمة الله
عندي سؤال كل ما احلو بيطلع الناتج غير متوقع مش عارف شو الخطا اللي في الحل , فاذا ممكن منكم المساعدة في ايجاد الخطا, مع العلم الي تقريبا اكتر من ساعة وانا باحاول اجد الخطا بس مش ملاقيه
السؤال هو
(Checking substrings) You can check whether a string is a substring of another string by using the indexOf<A name=the> method in the Stringhttp://' target="_blank"> class. Write your own method for this function. Write a program that prompts the user to enter two strings, and check whether the first string is a substring of the second.
ولقد قمت بكتابة الكود التالي ولكن الخطا الذي فيه هو انه دائما يطلع الناتج بان
the first string is a substring of the second.
import javax.swing.*;
public class S{
public static void main (String[] args){
String str1=JOptionPane.showInputDialog("Inter the first string :");
String str2=JOptionPane.showInputDialog("Inter the second string :");
String output="";
if(isSubString(str1,str2))
output="("+str1+") is a substring of ("+str2+")";
else
output="("+str1+") is not a substring of ("+str2+")";
JOptionPane.showMessageDialog(null,output);
}
public static boolean isSubString(String st1,String st2){
char[] n1=st1.toCharArray();
char[] n2=st2.toCharArray();
for (int i=0;i<n1.length;i++){
for (int j=0;j<n2.length;j++){
if(n1==n2[j])
return true;
}
}
return false;
}
}
