0% found this document useful (0 votes)
2 views

Assignment 3 PCP

The document contains a Java program that continuously prompts the user to input a student's name and two grades. It checks if the grades are non-negative and determines if the student has passed or failed based on the grades entered. The program outputs the student's name along with their pass/fail status accordingly.

Uploaded by

Ak-47
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Assignment 3 PCP

The document contains a Java program that continuously prompts the user to input a student's name and two grades. It checks if the grades are non-negative and determines if the student has passed or failed based on the grades entered. The program outputs the student's name along with their pass/fail status accordingly.

Uploaded by

Ak-47
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Assignment 3

import java.util.Scanner;
public class Assignment3 {
​ public static void main(String[] args) {
​ ​ Scanner input=new Scanner(System.in);// Creating an object named input for taking the inputs.
​ ​ while(true) {// This while loop will keep running the program
​ ​ System.out.println("Enter Students Name: ");// This will print the expression mentioned in "".
​ ​ String StudentName=input.next();// Taking String input from the user.
​ ​ System.out.println("Enter Grade 1:");// This will print the expression mentioned in "".
​ ​ int Grade1=input.nextInt();// Taking integer input from the user.
​ ​ System.out.println("Enter Grade 2:");// This will print the expression mentioned in "".
​ ​ int Grade2=input.nextInt();// Taking integer input from the user.
​ ​ if(Grade1<0 || Grade2<0){// If condition to validate that numbers are not less than 0.
​ ​ ​ System.out.println("Error: Grades cannot be Negative");// This will print the expression
mentioned in "".
​ ​ }
​ ​ else if(Grade1>=50 && Grade2>=50){// If condition to evaluate the student has passed if yes then
this loop will run.
​ ​ ​ System.out.println(StudentName+ " has passed the examination");// This will print the
name of student and expression mentioned in "".
​ ​ }
​ ​ else {// If student does not pass then this loop will run.
​ ​ ​ System.out.println(StudentName+ " has failed the examination");// This will print the name
of student and expression mentioned in "".
​ ​ }
​ ​ }
​ ​
​ }
}

You might also like