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

مساعدة بتصميم(شكل) السلاسل(Strings)

بدأه *en* في 15 أكتوبر 2010 · 9 رد · 559 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع
import java.util.Scanner;

//q1

public class integer {

     public  void fun()
     {


         Scanner input = new Scanner(System.in);




         int i;
         int sum = 0;
         int max = -9999;
         int min = 9999;
         int ne = 0;
         int no = 0;
         int n;
         double ave;

         System.out.print("Enter five integers:\n ");


         for (i = 1;i <= 5;i++){

             n = input.nextInt();

             sum = sum + n;


             if (n > max)
                 max = n;
             else
                 min = n;


             if (n % 2 == 0)
                 ne++;
             else
                 no++;

         }

         ave = (double) sum /5;

         System.out.printf("the sum : %d\n",sum);

         System.out.printf("the average : %d\n",ave);

         System.out.printf("the smallest number : %d\n",min);

         System.out.printf("the largest number : %d\n",max);

         System.out.printf("the total of odd number is : %d\n",no);

         System.out.printf("the total of even number is : %d\n",ne);











     }
}

هذا الmain

>>>>>>>>>>>>

public class q1 {

     public static void main(String[] args){


         integer myresult = new integer();

         myresult.fun();




     }
}

output

Enter five integers:

4

2

9

6

10

the sum : 31

the average : Exception in thread "main" java.util.IllegalFormatConversionException: d != java.lang.Double

at java.util.Formatter$FormatSpecifier.failConversion(Unknown Source)

at java.util.Formatter$FormatSpecifier.printInteger(Unknown Source)

at java.util.Formatter$FormatSpecifier.print(Unknown Source)

at java.util.Formatter.format(Unknown Source)

at java.io.PrintStream.format(Unknown Source)

at java.io.PrintStream.printf(Unknown Source)

at integer.fun(integer.java:52)

at q1.main(q1.java:9)

تم تعديل هذه المشاركة بواسطة .S.T.A.L.K.E.R في 15 أكتوبر 2010 في 13:16 — السبب: add code tag :@

#2

المشكله في هذا السطر :

System.out.printf("the average : %d\n", ave);

إجعله

System.out.printf("the average : %f\n", ave);

هل فطنت للمشكله؟؟؟

تم تعديل هذه المشاركة بواسطة هويدي في 15 أكتوبر 2010 في 02:22

#3

انا عملت كدة

و مش راضية تطلع معايا لغاية ما زهقت

00020309t.gif

1958_1963.gif
#4

:D...

بتستخدمي JDK كام؟ ..

#5
نفرتاري كتب:

انا عملت كدة

و مش راضية تطلع معايا لغاية ما زهقت

الداله

 printf(String format, Object... args)

مستخدمه منذ JDK 1.5

يعنى لو اقل من كدا مش هتشتغل

Software Developer
Mahmoudkelany.com


 

#6

قمت بتعديل العنوان بما يناسب المحتوى

ارجو اختيار عنوان مناسب في المواضيع القادمة

:cool:

#7

اسمحلي اخوي أنا يديده بالجافا توني ماأعرف هذي المسميات

اما بالنسبه لسؤال اختي هويدي أستخدم eclipse-SDK-3.6.1-win32

ومشكووووورين لكل من رد

=)

حليت المشكله

طلع الكوووووووووود

=)

i

[code]mport java.util.Scanner;

//q1

public class integer {

	 public  void fun()
	 {


		 Scanner input = new Scanner(System.in);




		 int i;
		 int sum = 0;
		 int max = -9999;
		 int min = 9999;
		 int ne = 0;
		 int no = 0;
		 int n;
		 double ave;

		 System.out.print("Enter five integers:\n");


		 for (i = 1;i <= 5;i++){

			 n = input.nextInt();

			 sum = sum + n;


			 if (n > max)
				 max = n;
			 if (n < min)
				 min = n;


			 if (n % 2 == 0)
				 ne++;
			 else
				 no++;

		 }

		 ave = (double) sum /5;

		 System.out.printf("the sum : %d\n",sum);

		 System.out.print("the average : ");

		 System.out.println(ave);


		 System.out.printf("the smallest number : %d\n",min);

		 System.out.printf("the largest number : %d\n",max);

		 System.out.printf("the total of odd number is : %d\n",no);

		 System.out.printf("the total of even number is : %d\n",ne);











	 }
}

//cont.q1  another file


public class q1 {

	 public static void main(String[] args){


		 integer myresult = new integer();

		 myresult.fun();

//output

/*

Enter five integers:

4

2

9

6

10

the sum : 31

the average : 6.2

the smallest number : 2

the largest number : 10

the total of odd number is : 1

the total of even number is : 4

*/

}

}

تم تعديل هذه المشاركة بواسطة .S.T.A.L.K.E.R في 16 أكتوبر 2010 في 13:19 — السبب: add console

#8
اقتباس
اختي هويدي

:haha: :haha: :haha: :haha: :haha:

تم تعديل هذه المشاركة بواسطة .S.T.A.L.K.E.R في 16 أكتوبر 2010 في 13:18

1 −1
#9

العفووووووووووو..

إذا مو اخت اعتذر

:mellow: :mellow:

#10

هويدى اسم رجل :)

وهو ونعم الرجال فى المنتدى

ربنا يوفققه ويوفقنا جميعا يارب :)

Software Developer
Mahmoudkelany.com


 

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