0% found this document useful (0 votes)
28 views

Sheet 1 - Java Basics

The document provides 6 programming problems: 1) a 3-digit number program from user input digits, 2) a power program calculating X^Y using loops, 3) a train time program computing trip duration from departure/arrival times, 4) a grades analysis program validating grades and calculating statistics, 5) a quadratic equation solver, 6) an element frequency counter between two arrays.

Uploaded by

rahmasalah862
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Sheet 1 - Java Basics

The document provides 6 programming problems: 1) a 3-digit number program from user input digits, 2) a power program calculating X^Y using loops, 3) a train time program computing trip duration from departure/arrival times, 4) a grades analysis program validating grades and calculating statistics, 5) a quadratic equation solver, 6) an element frequency counter between two arrays.

Uploaded by

rahmasalah862
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Menoufia University Advanced Programming Languages

Faculty of Electronic Engineering


Computer Science and Engineering
‫جام عة الم نوف ية‬

1. Write program that asks the user for three one-digit numbers and then uses
them as units, tens, and hundreds to evaluate one 3-digit number out of them
Example:
Please enter units: 5
Please enter tens: 2
Please enter tens: 9
The number is: 925
2. Write a program that gets two positive integer numbers X and Y and
calculates X^Y. (Hint: using loops with multiplication, i.e., X^Y = X*X*X*…
Y times)

3. Write a program that reads the departure time of a train and the arrival time
and computers and displays the trip time. (Example: for Departure time 10:50
and Arrival time 12:10 the trip time will be 1 hr and 20 min).

4. Write a program to read a list of student's grades from the user and do the
following:
a. Check each element to see if it is a valid grade (the valid range is from 0
to 100). For each grade, the program displays either Valid or Invalid.
Count the number of invalid grades.

b. Check each element to see if it is a valid grade (valid range is from 0 to


100). Produce a corresponding list (same size as the grades list) that has 1
or 0 in the same grade position; 1 if the grade is valid and 0 if it is invalid.
A grade list [90 -10 50 130 -2] will produce an output list [1 0 1 0 0]
c. Calculate and display the average grade.
d. Find and display the highest and lowest grades and specify their
locations.
e. Allocate and display students having grades greater than 85%, and
display their count.
f. Allocate and display students having grades greater than average, and
display their count.
5. Write a program that reads the coefficients (a, b, c) of the quadratic
equation ax2 + bx + c = 0. The program computes the roots (x1 and x2)

1
if they exist. The roots of the equations can be one of the following four
cases:
i. any x is a solution (if a = b = c = 0)
ii. no solution (if a = b = 0, c ~= 0)
iii. one real root (if a = 0, so the root is −c/b)
iv. two real or complex roots (if not any of the above cases)

Input Output

[0 0 0] Any x is a solution

[0 0 2] No solution

[0 1 3] -3

[1 -5 6] 2

6. Write a program to read two 1-D arrays from the user and compute how
many times each element in the first array occurs in the second array. Results
should be stored in an array.
Input [1 8 7 5] and [5 3 1 7 6 7 7] will produce output [1 0 3 1]

You might also like