0% found this document useful (0 votes)
13 views3 pages

Lab 7 (v4)

This document contains instructions for 4 programming assignments: 1. Print a pyramid pattern using nested for loops with symbols. 2. Calculate the average of numbers entered by the user using a while loop. 3. Find and display the product of the digits of a number entered by the user using a while loop, handling negative numbers. 4. Calculate the area of different shapes (circle, square, rectangle) selected by the user using a do-while loop, ensuring positive values.

Uploaded by

Noha Elzahar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views3 pages

Lab 7 (v4)

This document contains instructions for 4 programming assignments: 1. Print a pyramid pattern using nested for loops with symbols. 2. Calculate the average of numbers entered by the user using a while loop. 3. Find and display the product of the digits of a number entered by the user using a while loop, handling negative numbers. 4. Calculate the area of different shapes (circle, square, rectangle) selected by the user using a do-while loop, ensuring positive values.

Uploaded by

Noha Elzahar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Alamein University

Faculty of Computer science Structure Programming


& Engineering
Course Code: CSE014

Lab 7

1. Print a Pyramid Pattern


Write Java code using nested for loops to produce the following
modified output with symbols:
output:
*
*$*
*$*$*
*$*$*$*
*$*$*$*$*

2. Calculate the Average


Write a Java program that prompts the user to enter n
numbers. The program should then calculate and display the
average of the entered numbers using a while loop.
Sample Output:
Enter the number of values to be averaged: 5
Enter a number: 10
Enter a number: 5
Enter a number: 8
Enter a number: 12
Enter a number: 7
The average of the entered values: 8.4
3. Write a Java program that prompts the user to enter an integer.
The program should find and display the product of its
digits using a while loop. For negative numbers, return the
product as if the number were positive.

Sample Output:
Enter an integer: 789
Digits are 7 * 8 * 9
Product of the digits: 504

Page 1 of 5
Alamein University
Faculty of Computer science Structure Programming
& Engineering
Course Code: CSE014

4. Write a java program using a do while loop to calculate the area of


different
geometric shapes. The user should input his/her choice
according to the
displayed menu or input -3 to quit. The user should take
into consideration
the use of positive values while calculating the area.
Note:
Area of Circle = radius * radius * 3.14159.
Area of Rectangle = width * height
Area of a Square = Side * Side
Sample Output:
Enter your choice (-3 to Quit):
1. Area of Circle
2. Area of Square
3. Area of Rectangle
1
Enter the radius of the Circle:
-4

You should enter a positive value


Enter your choice (-3 to Quit):
1. Area of Circle
2. Area of Square
3. Area of Rectangle
2
Enter the Side of the Square:
3
The area of the Square with side 3 is: 9.0
Enter your choice (-3 to Quit):
1. Area of Circle
2. Area of Square
3. Area of Rectangle
3
Enter the width of the Rectangle:
-4
Enter the height of the
Rectangle: 2
You should enter positive
values
Enter your choice (-3 to Quit):
1. Area of Circle
2. Area of Square
3. Area of Rectangle
3
Enter the width of the Rectangle:
2
Page 2 of 5
Alamein University
Faculty of Computer science Structure Programming
& Engineering
Course Code: CSE014
Enter the height of the Rectangle:
3
The area of the Rectangle with width 2 and height 3 is
6.0
Enter your choice (-3 to Quit):
1. Area of Circle
2. Area of Square
3. Area of Rectangle
4

5. Write a program that produces the following output:: (Use at least one static
method besides main to help you.)

Page 3 of 5

You might also like