عرض مشاركة واحدة
منتديات طلاب وطالبات جامعة الملك عبد العزيز منتديات طلاب وطالبات جامعة الملك عبد العزيز
قديم 25-12-2011, 04:43 PM   #385

Prince soma

Super Hussam

الصورة الرمزية Prince soma

 
تاريخ التسجيل: Sep 2011
التخصص: IT
نوع الدراسة: إنتظام
المستوى: الرابع
الجنس: ذكر
المشاركات: 266
افتراضي رد: Cpcs 202 شروحات وحلول وواجبات الجافا

المشاركة الأصلية كتبت بواسطة فوضـى مشاهدة المشاركة
(counting positive and negative numbers and computing the average of numbers)
write a program that reads an unspecified number of integers, determines how many positive and negative values have been read, and computes the total and average of the input values (not counting zeros). your program ends with the input 0 . Display the average as a floating-point number.


run is:
كود PHP:
Enter an int valuethe program exits if the input is 0:
1 2 -1 3 0 
The number of positives is 3
The number of negatives is 1
The total is 5
The average is 1.25 

السلام عليكم
تكفون اللي يقدر يكتب خطوات البرامج
الاخراج موجود لكن محتاج ترتيب الخطوات .!نقرتين لعرض الصورة في صفحة مستقلة
تفضل هذا حل السؤال

كود PHP:
package javaapplication95;

import java.util.Scanner;

public class 
JavaApplication95 {
    
public static 
void main(String[] args) {

Scanner in = new Scanner(System.in);
System.out.print("Enter an int value, the program exits if the input is 0:  ");
int n in.nextInt();

int positives  0,  negatives=,  count 0;
double sum=ave=0;
for (; ;) {
  
sum+=n;
  
count++;
  
  
if (
== 0)
break;

if (
0) {

positives ++;
}
else{
    
negatives++;
}
avesum/count;



System.out.print("Enter an int value, the program exits if the input is 0:");
in.nextInt();
}
System.out.println("The number of positives " +  positives );

System.out.print("The number of negatives   " negatives );

System.out.println (" \n The total is " sum );
 
System.out.println (" The average is " ave );


}

إن شاء الله أكون ساعدتك

 

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