عرض مشاركة واحدة
منتديات طلاب وطالبات جامعة الملك عبد العزيز منتديات طلاب وطالبات جامعة الملك عبد العزيز
  #1  
قديم 19-04-2012, 10:19 PM
الصورة الرمزية ميم 28

ميم 28 ميم 28 غير متواجد حالياً

Amerah

 
تاريخ التسجيل: Sep 2010
نوع الدراسة: إنتظام
المستوى: الثالث
الجنس: أنثى
المشاركات: 192
افتراضي ياليت احد يساعدني في الشيت


من العنوان ابغى احد يساعدني في الشيت ضروري

. Write a Java program that will read words from the keyboard until the word doneis entered. For each word except done, report whether its first character is equal to its last character. For the required loop, use a
a. while statement
b. do-while statement

2. Convert the following code so that it uses nested while statements instead of for statements:

int s = 0;
int t = 1;
for (int i = 0; i < 10; i++)
{
s = s + i;
for (int j = i; j > 0; j--)
{
t = t * (j - i);
}
s = s * t;
System.out.println(“T is “ + t);
}
System.out.println(“S is “ + s);

. Suppose that you work for a beverage company. The company wants to know the optimal cost for a cylindrical container that holds a specified volume. Write a fragment of code that uses an ask-before-iterating loop. During each iteration of the loop, your code will ask the user to enter the volume and the radius of the cylinder. Compute and display the height and cost of the container. Use the following formulas, where V is the volume, r is the radius, h is the height, and C is the cost.


4. What does the following fragment of code display? What do you think the programmer intended the code to do, and how would you fix it?
int product = 1;
int max = 20;
for (int i = 0; i <= max; i++)
product = product * i;
System.out.println(“The product is “ + product);

. What does the following fragment of code display? What do you think the programmer intended the code to do, and how would you fix it?
int sum = 0;
int product = 1;
int max = 20;
for (int i = 1; i <= max; i++)
sum = sum + i;
product = product * i;
System.out.println(“The sum is “ + sum +
“ and the product is “ + product);

6. Write a for statement to compute the sum 1 + 22+ 32+ 42+ 52+ ... + n2.

7. (Optional) Repeat the previous question, but use the comma operator and omit the for statement’s body.


8. Suppose that we want to compute the geometric mean of a list of positive values. To compute the geometric mean of k values, multiply them all together and then compute the kth root of the value. For example, the geometric mean of 2, 5, and 7 is . Use a loop with a sentinel value to allow a user to enter an arbitrary number of values. Compute and display the geometric mean of all the values, excluding the sentinel. (Hint: Math.pow(x, 1.0 / k) will compute the kth root of x.


ياليت احد يساعدني وشكراا


رد مع اقتباس