• A.razaq

T11- Lets make our first full java program step by step

hello everyone , in this tutorial we will make our first fully operational java program from what we learned previously

this program will be easy to make and understand.

we learned in the previous tutorials how to use if and if..else statements

another way of using if statement is using the nested if statement

and nested if statement : means an if statement inside another if statement.

----------

lets make a program that test multiple cases and conditions using nested if statement

now our program will be a student grade marker

if the student grade >= 90 print (A)

else

if the student grade >= 80 print (B)

and so on

lets begin

first lets add a scanner class to our program as we learned before



import java.util.Scanner;


now lets create an object of the class scanner and name it "input "



Scanner input = new Scanner (System.in);



now lets ask the user to enter the grade and declare an integer variable named grade and take the input from the user using the scanner method ( nextInt)




System.out.println("Enter your grade");
		int grade = input.nextInt();


now lets make our nested if statement



if (grade>=90)
			System.out.println("A");
			else 
				 if (grade>=80)
					System.out.println("B");
				 else
					if (grade>=70)
						System.out.println("C");
					else
						if (grade>=60)
							System.out.println("D");
						else
							System.out.println("F");



now lets test our program


lets run the program and put 75 as a grade when the program ask


as you can see our input was 75 and the condition was for any grade from 70 or more the mark will be C


now lets try below 60



as you see, our input was 58 so the only matching condition is for any grade below 60 the mark will be F

------

i hope our tutorial was easy , follow every step and make your own version or a better version of this program.


A.razaq

5 views0 comments

Recent Posts

See All