请考虑下表了解不同公司的资格标准 -
cgpa
的中文翻译为:绩点平均成绩
符合条件的公司
大于或等于8
谷歌、微软、亚马逊、戴尔、英特尔、wipro
大于或等于7
教程点、accenture、infosys、emicon、rellins
大于或等于6
rtcamp、cybertech、skybags、killer、raymond
大于或等于5
patronics、鞋子、nobrokers
让我们进入 java 程序来检查 tpp 学生参加面试的资格。
方法1:使用if else if条件通常,当我们必须检查多个条件时,我们会使用 if else if 语句。它遵循自上而下的方法。
语法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}
示例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!); } }}
输出12109659 is eligible for companies: google, microsoft, amazon, capgemini, dell, intel, wiproe
在上面的代码中,我们声明并初始化了两个名为“regd”和“cgpa”的变量。当我们运行此代码时,编译器将检查第一个 if 条件,并且对于给定的“cgpa”值,它是 true。因此,它执行了第一个 if 块内的代码。
使用switch语句的方法switch 语句仅适用于 int、short、byte 和 char 数据类型。它不支持十进制值。它首先评估表达式,如果有任何情况匹配,它将执行该代码块。如果没有任何情况匹配,则执行默认情况。
语法// expression and value must be of same datatypeswitch(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}
示例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!); } } }
输出12109659 is eligible for companies: rtcamp, cybertech, skybags, killer, raymond
在上面的代码中,我们再次采用了相同的变量。由于 switch 与 double 变量不兼容,我们将其类型转换为名为“gpa”的整数类型变量。对于给定的“gpa”值,情况 6 与表达式匹配。因此,编译器执行了 case 6 代码。
方法三:使用用户自定义方法方法是可以多次重用以执行单个操作的代码块。它节省了我们的时间,也减少了代码的大小。
语法accessspecifier nonaccessmodifier return_type method_name(parameters){ //body of the method}
accessspecifier - 用于设置方法的可访问性。它可以是公共的、受保护的、默认的和私有的。
nonaccessmodifier - 它显示方法的附加功能或行为,例如静态和最终。
return_type − 方法将返回的数据类型。当方法不返回任何内容时,我们使用void关键字。
method_name - 方法的名称。
参数 - 它包含变量名称,后跟数据类型。
示例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); }}
输出12109659 is eligible for companies: tutorials point, accenture, infosys, emicon, rellins
上述程序的逻辑与我们在本文中讨论的第一个程序相同。主要区别在于我们创建了一个名为“eligible()”的用户定义方法,带有两个参数“regd”和“cgpa”,并且我们在主方法中使用两个参数调用了该方法。
结论在本文中,我们讨论了三种用于检查tpp学生是否有资格参加面试的java程序方法。我们看到了使用if else if条件和switch语句的用法。我们还为给定的问题创建了一个用户定义的方法。
以上就是java程序用于检查tpp学生是否有资格参加面试的详细内容。