[go: up one dir, main page]

0% found this document useful (0 votes)
27 views6 pages

Sample Quesions-1

This document provides a series of programming questions and problems to solve using concepts like loops, functions, arrays, and decision tables. Some examples include: 1. Writing a program to print numbers divisible by 5 within a range using do-while loops. 2. Applying control structures to write a program for multiplication or addition based on user input. 3. Creating functions to find the greatest of three or two numbers and calling them in a main program. 4. Solving various other programming challenges involving loops, functions, arrays, and decision tables.

Uploaded by

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

Sample Quesions-1

This document provides a series of programming questions and problems to solve using concepts like loops, functions, arrays, and decision tables. Some examples include: 1. Writing a program to print numbers divisible by 5 within a range using do-while loops. 2. Applying control structures to write a program for multiplication or addition based on user input. 3. Creating functions to find the greatest of three or two numbers and calling them in a main program. 4. Solving various other programming challenges involving loops, functions, arrays, and decision tables.

Uploaded by

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

Programming without boarder

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

39. You are given the following combination in painting room


Paint basic colors1 Red , Red and Blue , Paint Colors2 Blues Yellow and Yellow
Red+ Blue = Purple
Red + Yellow = Orange
Blue + yellow = Green
The resulting combination Purple , orange and green , Implement this in decision table
40. You have two type of employee those who are salary based and those who works on hourly
bases
The rules and condition work as follows
If employee is salary based and work on normal hours pay salary if works over 12 hours pay salary and
computer over time , if employee is hourly bases then only computer Hourly wages . if employee never
turn to the job produce absence report.
Implement the above in decision table.

41. You given the following information Read Income


If income is greater then cost calculates profit (Income –Cost) and prints profit report otherwise
calculate loss (Cost-Incomes) and generate loss report. Implement the above algorithm using flow chart
You are provided with two variables X1, X2 . You are required to print sum only if X2 is grater then X1
otherwise print. Implement this is flowchart

42. A technical support department write a decision table to diagnose printer problem based on
symptoms describes to them over the phone from clients

Condition: printer prints? A red light is flashing? Printer is recognized by computer?


Check the printer-computer cable, ensure printer software is installed , replace ink if printer does not
print but printer is recognized by computer but red light is flashing
Check for paper jam, check / replace ink if printer does not print but a red light is not flushing and
printer is recognized by computer
Check the power cable, check printer –computer cable and ensure printer software is installed if all
three cases are not working
Check paper jam only if printer is not recognized by computer
If printer is prints, a red light is flushing but print is not recognized then ensures printer software is
installed
If all cases are working then only check/replace ink
If only printer does not print then ensure printer software is installed
If only a red light is flushing and other case are ok then do nothing
Condition
Printer prints T T T T F F F F
A red light is flashing T T F F T T F F
Printer is recognized by T F T F T F T F
computer
Actions
Check the power cable x
Check the printer –computer x x
cables
Ensure printer software is x - x x x
installed

Check / replace ink x - x x


Check for paper jam - x x
43. In gun shooting a man can be considered dead if the were shoot and no more breathing.
Implement this in decision table
If shoot and not breathing then man dies, if shoot but there is breathing man is alive but injured, not
shoot but no breathing man dies.
44. The two roots of a quadratic equation ax2 + bx + c = 0
Can be obtained using the following formula:
r1 = -b + ((b2 - 4ac)1/2)/2a
and
r2 = -b - ((b2 - 4ac)1/2)/2a
(b2 - 4ac)is called the discriminant of the quadratic equation. If it is positive, the
equation has two real roots. If it is zero, the equation has one root. If it is negative,
the equation has no real roots.
Write a program that prompts the user to enter values for a, b, and c and displays
the result based on the discriminant. If the discriminant is positive, display two
roots. If the discriminant is 0, display one root. Otherwise, display “The equation
has no real roots”.

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

You might also like