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

deathpain

devkemo

الصورة الرمزية deathpain

 
تاريخ التسجيل: Dec 2010
كلية: كلية الحاسبات وتقنية المعلومات
التخصص: Computer Science
نوع الدراسة: إنتظام
المستوى: الثامن
البلد: جــــدة
الجنس: ذكر
المشاركات: 770
افتراضي رد: Cpcs 202 شروحات وحلول وواجبات الجافا

سؤال:
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 أيام ،، إذا كان هناك أي ملاحظات الرجاء إعلامي بذلك
وبالتوفيق للجميع

 

توقيع deathpain  

 



في حال وجود أي استفسار أو سؤال حول الجافا CPCS202 الرجاء كتابة استفسارك مباشرة في موضوعي هنا:

تطبيق - معدلي الجامعي - التطبيق الأسهل لحساب المعدل الجامعي
http://skaau.com/vb/showthread.php?t=745520

 

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