Control Statements and Basic Java Programs For Practice
In this article, we are going to cover some basic programs related to control statement learning.
Introduction:
Control statements are those which help programmers to execute program conditionally. Like If some condition is true then do something else do other things.
Control Statements are:
- If else
- if else if else
- switch
Loops:
Whenever we want to do some task repetitively we use loops there Like if we print numbers from 1 to 10. then either we can write 10 print statements or we can use for that.
Types of Loops:
- for loop: If we know in advance how many times we need to process data then we use for loop.
- Advance for loop: we can iterate using that also it is more easy syntax and new.
- while loop: If we don't know the number of times then while loop.
- do-while loop: It will execute the statement once even before checking the condition.
- forEach loop: This is advanced loop came in java 8.
15 Basic Programs to Practice:
1.Check whether a year is Leap Year or not.
2.Check whether a user is a Valid Voter or not.
3. Check whether a number is a Positive Number
4. Check whether a Number is Greater than 10
5. Find greatest among three numbers
6.Write a Java program that keeps a number from the user and generates an integer between 1 and 7 and displays the name of the weekday.
7.Write a Java program to find the number of days in a month
8.Write a program in Java to display the first 10 natural numbers
9.Write a program in Java to input 5 numbers from the keyboard and find their sum and average.
10. Write a program in Java to display the cube of the number upto a given an integer.
11.Write a program in Java to display the multiplication table of a given integer.
12.Check whether a given number is even or odd.
13.Check whether a given number is Palindrome Number
14.Check whether a given number is Armstrong Number
15. Find a Factorial of a number.
For the Solution to these programs, you can refer to my github. In the next article, I will give a solution also.
If you want to learn more join me on Linkedin. We are running live classes with a job guarantee.
Thanks for reading!