الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

ممكن وين الغلط

بدأه بنت السعوديه وبس في 23 مايو 2011 · 5 رد · 367 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم

انا قد كتبت سوال وهو المطلوب اني احل بكلاسين

وسويته بكلاسين

بس الغلط هنا المسافه ما يحسبه

اش الغلط

هذا المين :


// TODO code application logic here
String v;
Scanner s=new Scanner(System.in);
System.out.println("enter the string");
v=s.next();
Vowels obj=new Vowels(v);
obj.setCounters();
System.out.println("the a vowel found "+obj.getacount());
System.out.println("the o vowel found "+obj.getocount());
System.out.println("the e vowel found "+obj.getecount());
System.out.println("the i vowel found "+obj.geticount());
System.out.println("the u vowel found "+obj.getucount());
System.out.println("the spaces="+obj.getspaces());

}

}
 public static void main(String[] args) {

وهذا كلاس

package countvowels;
import java.util.*;

/**
 *
 * @author انس
 */
public class Vowels {
    private String str;
    private int acount;
    private int ocount;
    private int ecount;
    private int icount;
    private int ucount;
    private int spaces;
    public  Vowels(String s){
         acount=0;
         ocount=0;
         ecount=0;
         icount=0;
         ucount=0;
         spaces=0;
         str=s;
    }
public void setCounters(){
    for(int i=0; i<str.length(); i++)
    {
        if(str.charAt(i)=='a'||str.charAt(i)=='A')
            acount++;
        else if(str.charAt(i)=='o'||str.charAt(i)=='O')
            ocount++;
        else if(str.charAt(i)=='e'||str.charAt(i)=='E')
            ecount++;
        else if(str.charAt(i)=='i'||str.charAt(i)=='I')
                icount++;
        else if(str.charAt(i)=='u'||str.charAt(i)=='U')
                ucount++;
        elseif(str.charAt(i)==' ')
              spaces++;

    }
}
public int getacount(){
    return acount;

الله يسعدكم

#2

تفضلى

/**
 *
 * @author انس
 */
public class Vowels {

	private String str;
	private int acount;
	private int ocount;
	private int ecount;
	private int icount;
	private int ucount;
	private int spaces;

	public Vowels(String s) {
    	acount = 0;
    	ocount = 0;
    	ecount = 0;
    	icount = 0;
    	ucount = 0;
    	spaces = 0;
    	str = s;
	}

	public void setCounters() {
    	for (int i = 0; i < str.length(); i++) {
        	if (str.charAt(i) == 'a' || str.charAt(i) == 'A') {
            	acount++;
        	} else if (str.charAt(i) == 'o' || str.charAt(i) == 'O') {
            	ocount++;
        	} else if (str.charAt(i) == 'e' || str.charAt(i) == 'E') {
            	ecount++;
        	} else if (str.charAt(i) == 'i' || str.charAt(i) == 'I') {
            	icount++;
        	} else if (str.charAt(i) == 'u' || str.charAt(i) == 'U') {
            	ucount++;
        	} else if (str.charAt(i) == ' ') {
            	spaces++;
        	}

    	}
	}

	public int getAcount() {
    	return acount;
	}

	public int getEcount() {
    	return ecount;
	}

	public int getIcount() {
    	return icount;
	}

	public int getOcount() {
    	return ocount;
	}

	public int getSpaces() {
    	return spaces;
	}

	public int getUcount() {
    	return ucount;
	}
}

import java.util.Scanner;

/**
 *
 * @author JKelany
 */
public class MainVowels {

	public static void main(String[] args) {
    	String v;
    	Scanner s = new Scanner(System.in);
    	System.out.println("enter the string");
    	v = s.next();
    	Vowels obj = new Vowels(v);
    	obj.setCounters();
    	System.out.println("the a vowel found " + obj.getAcount());
    	System.out.println("the o vowel found " + obj.getOcount());
    	System.out.println("the e vowel found " + obj.getEcount());
    	System.out.println("the i vowel found " + obj.getIcount());
    	System.out.println("the u vowel found " + obj.getUcount());
    	System.out.println("the spaces=" + obj.getSpaces());
	}
}

Software Developer
Mahmoudkelany.com


 

#3

هذا :

 for(int i=0; i<str.length(); i++)
    {
        if(str.charAt(i)=='a'||str.charAt(i)=='A')
            acount++;
        else if(str.charAt(i)=='o'||str.charAt(i)=='O')
            ocount++;
        else if(str.charAt(i)=='e'||str.charAt(i)=='E')
            ecount++;
        else if(str.charAt(i)=='i'||str.charAt(i)=='I')
                icount++;
        else if(str.charAt(i)=='u'||str.charAt(i)=='U')
                ucount++;
        elseif(str.charAt(i)==' ')
              spaces++;

    }
}

, الجملة الاخيرة من المفروض تكون else فقط مو else if ,,

البرنامج شغال ؟

تم تعديل هذه المشاركة بواسطة Game111 في 24 مايو 2011 في 20:22

#4

مو فاهم ايه المشكله دلوقتى ؟؟؟

يعنى ايه الخطا فى الكود ؟

Software Developer
Mahmoudkelany.com


 

#5

مضبوط حلك يا Mahmoud Kelany و الخطأ ان ما في ميثود لاسترجاع عدد باقي الحروف

#6

مره يسلمو ربي يسعدكم طلع خطا بسيط ^_^

ربي يوفقكم

مواضيع مشابهة