• If you face “access denied” error, try removing read only attribute of both .java and .class files.
• Do not open files directly from TSR, copy to desktop and then double click to open.
• Learn how to take input from user/keyboard from the TSR folder,
Annajiat\CSE 110 lab and CSE 162\Labs\How to take input
• For anything that you forgot from CSE110/CSE161, also look up that from those folders or quickly search in the book using Ctrl+F.
Questions:
1. Write a Java program that would input ten numbers from the user and print the ten numbers in reverse order.
2. Write a Java program that will ask the user to enter 10 numbers and will verify the users input after each entry. For example if the user enters 2, the program will print “You have entered 2”, then if the user enters 4 the program will print “You have entered 2, 4”, then if the user enters 23 the program will print “You have entered 2, 4 , 23”. This will go on till the user enters the 10 numbers.
3. Write a Java program that would input ten numbers from the user and print the ten numbers sorted in descending order.
4. Write a Java program that would ask the user to enter five numbers. As the user enters the five numbers the program will make sure that all the numbers entered by the user are unique. For example if the user enters 2, 3, 4, 6, and then tries to enter 3 again the program will display that 3 is already in among the entered numbers and would ask the user to enter a new number. You will have to keep taking numbers from the user until you receive five unique numbers. At the end, print those five unique numbers.
5. The current in an alternating current circuit that contains resistance, capacitance, and inductance in series is given by
E
I =
2
R2 +2fL− 21fC
Where I=current (amperes), E=voltage (volts), R= resistance (ohms), L= inductance (henrys), C= capacitance (farads) and f=frequency (hertz). Write a Java program that reads values for the voltage, resistance, inductance, capacitance and frequency, and then calculates and displays current.
Page 1 of 2
6. Write a Java program that will calculate the value of y if the expression of y is as follows (n is the input):
y= 12 − 22 + 32 − 42 +52 ............ +n2
Homework:
7. Modify your solution for the question number 4. Take 11 numbers such that any numbers can exist at maximum four times. That means any number can be entered multiple times but when the use enters same numbers for 5th time, it should reject and ask for any other number but that number.
e.g. Imagine the user entered 3,2,5,7,2,3,2,0,9,2,3. If the user tries to enter 2 again, it must not allow it because 2 is already there, 4 times.
8. Modify your solution of number 7. Take 10 numbers within 0 to 9. When you print output, users will see only the numbers that appeared at least twice and less than 5 times. e.g. Imagine the user entered 4,3,2,5,2,3,2,0,2,3 then the output is 3, 2.
9. Modify your solution of number 3. Ask user if the user wants to sort
a) only numbers at odd positions Or, b) only numbers at even positions
Or, c) all numbers (means numbers at all positions)
And then sort only the numbers that the user wanted to be sorted as if all other numbers do not exist.
When printing, print all numbers.
10. Modify your solution of number 8. Take as many numbers within 0 to 9 as needed so that you can print 2 such number that appeared at least twice and less than 5 times. e.g. Imagine the user entered 4,3,2,5,2,3,2,0,2,3 then the output is 3, 2.
Page 2 of 2