عرض مشاركة واحدة
منتديات طلاب وطالبات جامعة الملك عبد العزيز منتديات طلاب وطالبات جامعة الملك عبد العزيز
قديم 29-11-2011, 09:20 PM   #11

SoSoooo B

جامعي

الصورة الرمزية SoSoooo B

 
تاريخ التسجيل: Jul 2010
التخصص: Cs
نوع الدراسة: إنتظام
المستوى: الخامس
الجنس: أنثى
المشاركات: 1,151
افتراضي رد: Cpcs 202 شروحات وحلول وواجبات الجافا

المشاركة الأصلية كتبت بواسطة deathpain مشاهدة المشاركة
سؤال:
Write a program that reads integers, finds the smallest of them, and counts
its occurrences. Assume that the input ends with number 0. Suppose that
you entered 30 50 20 50 20 50 100 0; the program finds that the smallest is
20 and the occurrence count for 20 is 2.
If the occurrences of the smallest number is greater than 1, print the value
of the number and the number of occurrences. However, if the smallest
number occurrences is equal 1, print only the value of the smallest number.
Note: The occurrences of a number means how many times this number has
been entered in the input.
في هذا السؤال طلب مننا نسوي برنامج يخلي المستخدم يدخل مجموعة من الأعداد الصحيحة ويقوم البرنامج بحساب أقل قيمة مدخلة وعدد مرات تكرارها، وإذا أدخل المستخدم رقم 0 فالبرنامج يتوقف عن إدخال الأرقام،
إذا كان عدد مرات التكرار أكثر من 1 فعلى البرنامج طباعة أقل رقم مدخل + عدد مرات تكراره
أما إذا كان عدد مرات التكرار مرة واحدة فعلى البرنامج طباعة أقل رقم مدخل فقط ،،

الحل:
كود PHP:
import java.util.*;
/
 *
 * @
author deathpa1n
 
*/
public class 
javaapplication104 {
    public static 
void main(string[] args) {
        
int occurrences=1,smallest=0,num;
scanner input = new scanner(system.in);
system.out.print("enter a number: ");
num input.nextint();
while (
num <= 0){
system.out.println("you cannot enter 0 or negative number as a first number!");
system.out.print("enter a number: ");
num input.nextint();}
smallest num;
while(
true){
system.out.print("enter a number: ");
num input.nextint();
if(
num <= 0) break;
if(
num smallest){
smallest num;
occurrences 0;}
if(
num == smallestoccurrences++;}
if (
occurrences==1)
system.out.println("the smallest is: "+smallest);
else 
system.out.println("the smallest is: "+smallest+" and it's occurrences: "+occurrences);
}

البرنامج هذا استغرق حله 4 أيام ،، إذا كان هناك أي ملاحظات الرجاء إعلامي بذلك
وبالتوفيق للجميع
جزاك الله خير بس الاسئلة دي من فين تجيبها ؟

 

SoSoooo B غير متواجد حالياً   رد مع اقتباس