بسم الله الرحمن الرحيم
يا جماعة حد يساعدنا في ايجاد المشكلة
لقد قمت بكتابة الكود الذي في الاخر وهو لاحصاء عدد كل رقم من 1 الى 9 يقوم المستخدم بادخالها عن طريق سترنج
والمهم بعد كتابة البرنامج ضغطت على الكمبايل فقال ان العملية تمت (اي لا يوجد اخطاء), ولكن عندما ضغطت على الرن لم يعمل البرنامج فماذا تكون المشكلة؟
هل المشكلة في البرنامج نفسه ام في الكود ام في ماذا
مع العلم ان صيغة السؤال هكذا
Write a method that counts the occurrences of each digit in a string using the following header:
public static int[] count(String s)
The method counts how many times a digit appears in the string. The return value is an array of ten elements, each of which holds the count for a digit. For example, after executing http://' target="_blank">int[] counts = count("12203AB3"), counts[0] is 1, counts[1] is 1, counts[2] is 2, counts[3] is 2.
والكود الذي قمت بكتابته هو
import javax.swing.*;
public class X{
public static void main (String[] args){
String s=JOptionPane.showInputDialog("Inter the string :");
int[]counts= count(s);
String output="";
for (int i=0;i<counts.length;i++){
if(counts!=0)
output+="The num ("+ i +") is appears "+ counts+ ((counts==1) ? " time\n":" times\n");
}
JOptionPane.showMessageDialog(null,output);
}
public static int[] count(String s){
int[]counts=new int[10];
for(int i=0;i<s.length();i++){
if(Character.isDigit(s.charAt(i)))
counts[s.charAt(i)]++;
}
return counts;
}
}