Sample Quesions-1
Sample Quesions-1
Questions
1. Using do while write a sample program that will print numbers that are dividable by 5
between two given numbers that are read from the key board
2. Apply control structure to write a sample program that does multiplication or addition when the
user passes the parameters. For example “ M” for multiplication “A” for addition “D” for
division , “S” for subtraction and R for remainder
3. Write two function with argument that will display the greatest of three numbers and of two
numbers finally write main program and call the two function to the main by passing
parameters
4. Write a program that will solve quadratic equation by allowing user to provided value of A,B
and C
5. Using for loop write a program that will display the time table of 1 to 12
6. Applying if and switch case write a program that will allow user to enter choice and the program
do addition. Subtraction, multiplication, division and remainder operation. The choices are enter
from the key board and the value are also entered from keyboard
7. Write a program that uses multiple switch case and print out quarter of the month
8. Given an array of int []= {7.10.15 17,21} write a program that and pass this array to the
function and finally display the contents
9. Given an array of Double [] arrD ={21.5,38.5 71.6 81.5}.Write a program using for each loop
that will sum item of the array and also give the average
10. Using while loop display number between 100 and 200 which are divisible by 3
11. Given and investment of 1M with a condition that if the money stay in the bank for more
than 10 year your interest is 0.5 annually otherwise your interest is 0.3 annually . Write a
program that will compute interest and total amount. user is allowed to enter year from the
keyboard
12. You are given an array of integers int []= { 43, 54 , 24, 65, 78, 85, 88, 92, 10}
13. Required: (i) write a function that will find maximum of the item in the array (ii) write a
function that will find minimum of the array (ii) create main program and call the function to
the main program
14. Given an array of {20, 30, 40,50 , 60, 70, 80, 90, 10} write a program that will such a any
number in the array . The search element is entered from the keyboard
15. Show how to pass a variable to the function. Demonstrate by developing a function that
compare two numbers
16. Write function that will create arrays and return integers generated from keyboards
17. Write a function that will allow passing the array you created above and return maximum
18. Write a function that will allow passing the array you created above and return minimum
19. Write a function that will allow passing the array you created above and return sum and average
of the arrays
20. Write a function that will return the largest of three numbers
21. Write a simple program using while loop that will return the sum of numbers from 1 to 100
22. You are given the following array of characters myArray = { 'H', 'e', 'l', 'l', 'o' }; write a simple
program using for each loop that will display the word “Hello”. How can you display the same
using for Loop?
23. You are provided with variable string[] colors = new string[3] and string[] colors2 = new
string[3] { "Red", "Blue", "Pink" } Show using for loop how to assign array colors2 to array
colors
24. You are given a variable String[] ret_Array = {" C#","Java", "C++","Python", "Ruby", "C","VB",
"VB.net", "Php"} write a simple program that will return this array a another array variable.
25. You are given array int[] myArray = { 43, 54, 23, 65, 78, 85, 88, 92, 10 }; Write a simple function
accept array as parameter and compute the minimum and maximum of the array. Proceed
and write another function that will sum the element of the array and get the average
26. You are given the following country having different spoken language write as simple switch
case program that display language of person from respective country{ Country include
America, UK, French, Tanzania, Kenya and Kongo }
27. Using while loop write simple program that will return prime factors of number 135
28. Write a program to design and implement a simple calculator which shall perform the following
operations. Implement this program using condition statement
a. Addition
b. Subtraction
c. Multiplication and
d. Division
e. Remainder
29. Using while loop write a program that will return the sum of all even numbers between 1 and
100
30. Using any control structure you learned write a program to compute and display the roots of a
quadratic equation. The program must validate and state whether the roots are either real roots
or complex roots or equal roots.
31. Write a program to compare the three integers and state the most or biggest integer. The
output must be formatted as [ 25 is the largest of 23 and 12]
32. Write a program to accept student`s scores. The program must validate scores and Print (score,
Grade and status) based on the range provided bellow.
33.
Score Grade Status
100-80 A Excellent
80-60 B Very Good
60-40 C Pass
40-0 F Failed
Above 100 and NO Grade Out Of range
below 0
34. Using the concept function write a program to implement a function which must return the
factorial of a number and for loop
35. Write a program to implement an array of velocity VEL [size], the program must read inputs
from user inputs and display them.
36. You are subjected to bank problem to that you can only draw some cash if with draw amount is
less than balances and also if the credit card is grated for password. You have three actions to
take grant withdrawing if both cases are valid and not granting withdraws if both cases are not
valid but you can Consult Bank manager if card not grated but balance is available and it is
within drawing amount Write a decision table to implement the problem
Condition Rule
Withdrawal Amount <Balance T T F F
Is Credit card Granted T F T F
Action entry
Action
Withdraw Granted x
No withdraw x x
Consult Bank manager x
37. You are given the following summary information that two team players name Team A and
Team B do play and can have three possible outcome Team A can win the game/ match or
Team B can win match or Both can score draw. Write a Decision table to implement all
possible outcome
Condition Rule
TEAM A T T F F
TEAM B T F T F
Action entry
TEAM A WIN x
TEAM B WIN x
Both are Draw x x
38. You are given the situation that that You can send email when recipient address is present,
when subject is written and must be done before end of work hour 5:30. If email is written after
work hours then put in pending folder, If recipient address are missing or subject is missing in a
message then give error message
Condition
Address present T T T T F F F F
Subject written T T F F T T F F
Time Before 5:30 T F T F T F T F
Actions
Send mail x
Error Message x x x x x x
Make pending x
42. A technical support department write a decision table to diagnose printer problem based on
symptoms describes to them over the phone from clients
45. Are there any performance differences between the following two import
statements?
import javax.swing.JOptionPane;
import javax.swing.*;
46. Using concept of function Write a program that reads a Celsius degree in
double from the console, then converts it to Fahrenheit and displays the result. The
formula for the conversion is as follows:
fahrenheit = (9 / 5) * celsius + 32.
47. Using concept of function Write a program that reads a Fahrenhe degree in
double from the console, then converts it to Celsius it and displays the result. The
formula for the conversion is as follows:
fahrenheit = (9 / 5) * celsius + 32.
48. Identify and fix the errors in the following code:
public class Test {
public void main(string[] args) {
inti;
int k = 100.0;
int j = i + 1;
System.out.println("j is " + j + " and 8 k is " + k);
}
}
49. What data types are required for a switch variable? If the keyword break is not
used after a case is processed, what is the next statement to be executed?
50. Identify and fix the errors in the following code indicate the error and line:
public class Test {
public void main(String[] args) {
for (inti = 0; i< 10; i++);
sum += i;
if (i< j);
System.out.println(i)
else
System.out.println(j);
while (j < 10);
{
j++;
};
do {
j++;
} while (j < 10)
}
}
51. Write an abstract class Geofig with data members Point and sides. abstact methods getArea and
getPerimeter.
52. Write two classes Rectangle and RightTriangle which inherit from Geofig. Write a test class to
define the area nad perimeter of the two class objects
53. What is apatial function write a simple partial function t that will read employee data and
compute their monthly salary and deduction
54. What is class and what is an object : write a simple class and show how you can create object
from that class