Lab 7 (v4)

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 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