Java program used to check if TPP students are eligible for interviews
Please consider the table below to know the eligibility criteria of different companies -
CGPA | is: Grade Point Average |
Eligible companies |
---|---|---|
is greater than or equal to 8 |
Google, Microsoft, Amazon, Dell, Intel, Wipro |
|
is greater than or equal to 7 |
Tutorial point, accent, Infosys, Emicon, Rellins |
|
is greater than or equal to 6 |
rtCamp、Cybertech、Skybags、Killer、Raymond |
|
is greater than or equal to 5 |
Patronics, Shoes, NoBrokers |
Let us enter the java program to check the eligibility of tpp students for interview.
Method 1: Use if else if condition
Usually, when we have to check multiple conditions, we use if else if statement. It follows a top-down approach.
grammar
if(condition 1) { // code will be executed only when condition 1 is true } else if(condition 2) { // code will be executed only when condition 2 is true } else { // code will be executed when all of the above condition is false }
Example
public class Eligible { public static void main(String[] args) { int regd = 12109659; double CGPA = 8.08; if( CGPA >= 8 ) { System.out.println(regd + " is eligible for companies: Google, Microsoft, Amazon, Capgemini, Dell, Intel, Wipro"); } else if(CGPA >= 7) { System.out.println(regd + " is eligible for companies: Tutorials point, accenture, Infosys, Emicon, Rellins"); } else if(CGPA >= 6) { System.out.println(regd + " is eligible for companies: rtCamp, Cybertech, Skybags, Killer, Raymond"); } else if( CGPA >= 5 ) { System.out.println(regd + " is eligible for companies: Patronics, Bata, Nobroker"); } else { System.out.println("Improve yourself!"); } } }
Output
12109659 is eligible for companies: Google, Microsoft, Amazon, Capgemini, Dell, Intel, Wiproe
In the above code, we declare and initialize two variables named "regd" and "CGPA". When we run this code, the compiler will check the first if condition and for the given "CGPA" value, it is true. Therefore, it executes the code inside the first if block.
How to use Switch statement
The switch statement is only available for int, short, byte and char data types. It does not support decimal values. It first evaluates the expression and if any of the conditions match, it executes the block of code. If no cases match, the default case is executed.
grammar
// expression and value must be of same datatype switch(expression) { case value: // code will be executed only when the expression and case value matched break; case value: // code will be executed only when the expression and case value matched break; . . . case value n: // n is required number of value default: // If none of the case matched then it will be executed }
Example
public class Main { public static void main(String[] args){ int regd = 12109659; double CGPA = 6.55; int GPA = (int) CGPA; // typecasting double to integer type switch(GPA){ // here GPA = 6 case 10: case 9: case 8: System.out.println(regd + " is eligible for companies: Google, Microsoft, Amazon, Capgemini, Dell, Intel, Wipro"); break; case 7: System.out.println(regd + " is eligible for companies: Tutorials point, accenture, Infosys, Emicon, Rellins"); break; case 6: System.out.println(regd + " is eligible for companies: rtCamp, Cybertech, Skybags, Killer, Raymond"); break; case 5: System.out.println(regd + " is eligible for companies: Patronics, Bata, Nobroker"); break; default: System.out.println("Improve yourself!"); } } }
Output
12109659 is eligible for companies: rtCamp, Cybertech, Skybags, Killer, Raymond
In the above code, we have used the same variable again. Since switch is not compatible with double variables, we typecast it to an integer type variable named "GPA". Case 6 matches the expression for the given value of "GPA". Therefore, the compiler executes the case 6 code.
Method 3: Use user-defined method
Methods are blocks of code that can be reused multiple times to perform a single operation. It saves us time and also reduces code size.
grammar
accessSpecifier nonAccessModifier return_Type method_Name(Parameters){ //Body of the method }
accessSpecifier - used to set the accessibility of a method. It can be public, protected, default, and private.
nonAccessModifier - It shows additional functionality or behavior of a method such as static and final.
return_Type − The data type that the method will return. We use void keyword when the method does not return anything.
method_Name - The name of the method.
Parameters - It contains the variable name followed by the data type.
Example
public class Main { public static void eligible(int regd, double CGPA){ if(CGPA >= 8){ System.out.println(regd + " is eligible for companies: Google, Microsoft, Amazon, Capgemini, Dell, Intel, Wipro"); } else if(CGPA >= 7){ System.out.println(regd + " is eligible for companies: Tutorials point, accenture, Infosys, Emicon, Rellins"); } else if(CGPA >= 6){ System.out.println(regd + " is eligible for companies: rtCamp, Cybertech, Skybags, Killer, Raymond"); } else if(CGPA >= 5){ System.out.println(regd + " is eligible for companies: Patronics, Bata, Nobroker"); } else { System.out.println("Improve yourself!"); } } public static void main(String[] args){ eligible(12109659, 7.89); } }
Output
12109659 is eligible for companies: Tutorials point, accenture, Infosys, Emicon, Rellins
The logic of the above program is the same as the first program we discussed in this article. The main difference is that we created a user-defined method called "eligible()" with two parameters "regd" and "CGPA" and we called that method with two parameters in the main method.
in conclusion
In this article, we have discussed three java program methods for checking whether a tpp student is eligible for interview. We saw the use of if else if condition and switch statement. We also created a user-defined method for a given problem.
The above is the detailed content of Java program used to check if TPP students are eligible for interviews. For more information, please follow other related articles on the PHP Chinese website!

Start Spring using IntelliJIDEAUltimate version...

When using MyBatis-Plus or other ORM frameworks for database operations, it is often necessary to construct query conditions based on the attribute name of the entity class. If you manually every time...

Java...

How does the Redis caching solution realize the requirements of product ranking list? During the development process, we often need to deal with the requirements of rankings, such as displaying a...

Conversion of Java Objects and Arrays: In-depth discussion of the risks and correct methods of cast type conversion Many Java beginners will encounter the conversion of an object into an array...

Solutions to convert names to numbers to implement sorting In many application scenarios, users may need to sort in groups, especially in one...

Detailed explanation of the design of SKU and SPU tables on e-commerce platforms This article will discuss the database design issues of SKU and SPU in e-commerce platforms, especially how to deal with user-defined sales...

How to set the SpringBoot project default run configuration list in Idea using IntelliJ...


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver CS6
Visual web development tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment