Pages

15 most challenging programming assignments | Java

The best way to learn is to do.

Its fun to learn a programming language and concepts by solving challenges. I have been teaching programming to some of the students, and I collected these assignments for them. These should help others too.

Here goes the questions.

1. Write a program to check if a number is even or odd. The program should ask for an integer input, and then check if the input is even or odd
and print the appropriate message.(Hint: divided by 2 if the remainder is 0 then its even)

2. Write a program to find if a number is prime in java.(Division up to the square root is enough)

3. Find if a number is power of 2 in java. (Hint: one possible solution is using bit shift operator)

4. Write a program to sort an integer array without using the inbuilt methods provided by java.

5. Write a program in java to check if a number is an armstrong number.
(Hint: An armstrong number is a number whose sum of the cube of its digits is equal to the number.
eg 153 = 1*1*1 + 5*5*5+3*3*3)

6. Write a program to reverse any string in java.(you could use iterative method or recursive method. Try implementing both)

7. Write a program in Java to print Fibonacci series up to given number? Try both iterative and recursive version.

8. Write a program in java to calculate factorial of an integer number.(Iterative, Recursive)

9. Write a program in java that will ask for an integer input and then print a pattern.
(for eg. if the input is 5)
*
**
***
****
*****
****
***
**
*
10. Write a program that displays the temperatures from 0 degrees Celsius to 100 degrees Celsius and its Fahrenheit equivalent. Note that the conversion from Celsius to Fahrenheit uses the following formula: F = C * 9/5 + 32;

11. Write a program to find the number of and sum of all integers greater than 100 and less than 200 that are divisible by 7.

12. Write a number guessing game. The program will ask for an input(1 to 5). Then it should generate a random number and check if its matches with the users input. The program should do this ten times for a user, and then finally prints the score of the user.

13. In the above program, add a method to save the final score in a file if it is the highest one. The next time another user plays the game, the program should read the previous score from the file. if the current score is greater than the previous score, the program should print "You are the new winner", and then save the new highest score in the file before exiting. If the file is not present, the program should create a new one.

14. Write a program that will prompt "Enter a command".
- If you enter "pwd", it should print the current directory's location.
- if you enter "ls", it should print the name of all the files and directory's in the current directory.
- if you enter "exit", the program should exit.
- if you enter "help", it should print a help text about the commands it support and what they do.

15. Write a program that will prompt "Enter a command".
- if you enter "ls", it should print the name of all the files and directory's in the current directory.
- if you enter "ls | grep <pattern>", the program should print all the files and directories that match the <pattern>
- if you enter "exit" the program should exit.

No comments:

Post a Comment

If you like to say anything (good/bad), Please do not hesitate...