英文:
Highest Value among 3 Numbers
问题
import java.util.*;
class Placement {
public static void main(String[] args) {
int x, y, z;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the no of students placed in CSE: ");
x = sc.nextInt();
System.out.println("Enter the no of students placed in ECE:");
y = sc.nextInt();
System.out.println("Enter the no of students placed in MECH:");
z = sc.nextInt();
if (x == y && y == z && z == x) {
System.out.println("None of the department has got the highest placement");
} else if (x < 0 || y < 0 || z < 0) {
System.out.println("Input is Invalid");
} else {
System.out.println("Highest placement");
if (x >= y && x >= z) {
if (x == y) {
System.out.println("CSE");
System.out.println("ISE");
} else if (x == z) {
System.out.println("CSE");
System.out.println("MECH");
} else {
System.out.println("CSE");
}
} else if (y >= z) {
if (y == z) {
System.out.println("ECE");
System.out.println("MECH");
} else {
System.out.println("ECE");
}
} else {
System.out.println("MECH");
}
}
}
}
Note: I've corrected the misspelled methods printIn
to println
and the comparison operators (>=
, <=
, ==
) in the code. The corrected code should address the issues you were facing.
英文:
PROBLEM STATEMENT : SRV college wants to recognize the department which has succeeded in getting the maximum number of placements for this academic year. The departments that have participated in the recruitment drive are CSE,ECE, MECH. Help the college find the department getting maximum placements. Check for all the possible output given in the sample snapshot
Note : If any input is negative, the output should be "Input is invalid". If all department has equal number of placements, the output should be "None of the department has got the highest placement".
Sample Input 1:
Enter the no of students placed in CSE:90
Enter the no of students placed in ECE:45
Enter the no of students placed in MECH:70
Sample Output 1:
Highest placement
CSE
Sample Input 2:
Enter the no of students placed in CSE:55
Enter the no of students placed in ECE:85
Enter the no of students placed in MECH:85
Sample Output 2:
Highest placement
ECE
MECH
Sample Input 3:
Enter the no of students placed in CSE:0
Enter the no of students placed in ECE:0
Enter the no of students placed in MECH:0
Sample Output 3:
None of the department has got the highest placement
Sample Input 4:
Enter the no of students placed in CSE:10
Enter the no of students placed in ECE:-50
Enter the no of students placed in MECH:40
Sample Output 3:
Input is Invalid
I was able to come up with a code which basically passes all the visible condition, but failing to test one. Not really sure where I am going wrong.
I totally agree the below code isn't the efficient
import java.util.*;
class Placement{
public static void main(String[] args) {
int x,y ,z ;
scanner sc= new Scanner(System.in) ;
System.out.printIn( "Enter the no of students placed in CSE: " );
x=sc.nextInt( );
System.out.printIn("Enter the no of students placed in ECE:" );
y=sc.nextInt( ) ;
System.out.println("Enter the no of students placed in MECH:" );
z=sc.nextInt( ) ;
if(x==z && x==y && y==z){
System.out.printIn("None of the department has got the highest placement" ) ;
}
else if(x<0 || y<0 || z<0){
System.out.printIn("Input is Invalid" ) ;
}
else{
System.out.println( "Highest placement" );
if(x>=z && x>=z){
if(x==y){
System.out.printIn( "CSE" );
System.out.printIn("ISE" );
}
else if(x==z) {
System.out.printIn("CSE" ) ;
System.out.printIn( "MECH" ) ;
}
else{
System.out.println("CSE" );
}
}
else if(y>=z){
{
if(y==z){
System.out.printIn( "ECE" );
System.out.printIn( "MECH" ) ;
}
else{
System.out.println("ECE" ) ;
}
else{
System.out.printIn( "MECH" ) ;
}
}
}
OUTPUT:
Proposed grade: 85. 71 / 100
Result Description
Failed tests
Test 2: CheckConditionsForTwoMax
Test 1: Check Conditions
Summary of tests
*Note: All the test cases might not have same weightage
7 tests run/ 6 tests passed
答案1
得分: 0
// 修复了错误,虽然不是最高效的答案,但已经可以工作。
import java.util.*;
class Placement {
public static void main(String[] args) {
int a, b, c;
Scanner sc = new Scanner(System.in);
System.out.println("输入已被安置在计算机科学与工程(CSE)的学生人数:");
a = sc.nextInt();
System.out.println("输入已被安置在电子与通信工程(ECE)的学生人数:");
b = sc.nextInt();
System.out.println("输入已被安置在机械工程(MECH)的学生人数:");
c = sc.nextInt();
if (a > b && a > c) {
System.out.println("最高安置量");
System.out.println("CSE");
} else if (a < 0 || b < 0 || c < 0) {
System.out.println("输入无效");
} else if (b > a && b > c) {
System.out.println("最高安置量");
System.out.println("ECE");
} else if (c > a && c > b) {
System.out.println("最高安置量");
System.out.println("MECH");
} else if (a == b && b == c && c == a) {
System.out.println("没有任何系获得最高安置量");
} else if (a == b) {
System.out.println("最高安置量");
System.out.println("CSE");
System.out.println("ECE");
} else if (a == c) {
System.out.println("最高安置量");
System.out.println("CSE");
System.out.println("MECH");
} else {
System.out.println("最高安置量");
System.out.println("ECE");
System.out.println("MECH");
}
}
}
英文:
Well figured out the mistake, not the efficient answer but got it working.
import java.util.*;
class Placement{
public static void main(String[ ] args){
int a, b, c;
Scanner sc= new Scanner(System. in) ;
System.out.println("Enter the no of students placed in CSE:");
a=sc.nextInt();
System.out.println("Enter the no of students placed in ECE:");
b=sc.nextInt();
System.out.println("Enter the no of students placed in MECH:");
c=sc.nextInt();
if (a>b && a>c){
System.out.println("Highest placement" ) ;
System.out.println("CSE");
}
else if(a<0 || b<0 || c<0){
System.out.println("Input is Invalid");
}
else if(b>a && b>c){
System.out.println("Highest placement") ;
System.out.println("ECE") ;
}
else if(c>a && c>b){
System.out.println("Highest placement") ;
System.out.println( "MECH" ) ;
}
else if(a==b && b==c && c==a){
System.out.println( "None of the department has got the highest placement" ) ;
}
else if(a==b){
System.out.println("Highest placement");
System.out.println("CSE");
System.out.println("ECE");
}
else if(a==c){
System.out.println("Highest placement");
System.out.println("CSE") ;
System.out.println("MECH") ;
}
else{
System.out.println("Highest placement");
System.out.println("ECE") ;
System.out.println("MECH") ;
}
}
}
答案2
得分: 0
唯一的错误是你在 a==b 的条件中输入了 ICE 而不是 ECE。
英文:
The only mistake was you have typed ICE instead of ECE in a==b condition
答案3
得分: 0
import java.io.*;
import java.util.*;
public class Placement {
public static void main(String[] args) {
int ece, cse, mech;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the no of students placed in CSE:");
cse = sc.nextInt();
System.out.println("Enter the no of students placed in ECE:");
ece = sc.nextInt();
System.out.println("Enter the no of students placed in MECH:");
mech = sc.nextInt();
sc.close();
if (ece == cse && ece == mech)
System.out.println("None of the departments has got the highest placement");
else if (ece < 0 || cse < 0 || mech < 0)
System.out.println("Input is Invalid");
else {
System.out.println("Highest placement");
if ((cse >= ece) && (cse >= mech))
if (cse == ece)
System.out.println("CSE" + "\nECE");
else if (cse == mech)
System.out.println("CSE\n" + "MECH");
else
System.out.println("CSE");
else if (ece >= mech && ece >= cse)
if (ece == mech)
System.out.println("ECE\n" + "MECH");
else if (ece == cse)
System.out.println("ECE\n" + "CSE");
else
System.out.println("ECE");
else
System.out.println("MECH");
}
}
}
英文:
import java.io.*;
import java.util.*;
public class Placement{
public static void main (String[] args) {
int ece,cse,mech;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the no of students placed in CSE:");
cse=sc.nextInt();
System.out.println("Enter the no of students placed in ECE:");
ece=sc.nextInt();
System.out.println("Enter the no of students placed in MECH:");
mech=sc.nextInt();
sc.close();
if(ece==cse&&ece==mech)
System.out.println("None of the departments has got the highest placement");
else if (ece<0||cse<0||mech<0)
System.out.println("Input is Invalid");
else
{
System.out.println("Highest placement");
if((cse>=ece)&&(cse>=mech))
if(cse==ece)
System.out.println("CSE"+"\nECE");
else if (cse==mech)
System.out.println("CSE\n"+"MECH");
else
System.out.println("CSE");
else if (ece>=mech&&ece>=cse)
if(ece==mech)
System.out.println("ECE\n"+"MECH");
else if(ece==cse)
System.out.println("ECE\n"+"CSE");
else
System.out.println("ECE");
else
System.out.println("MECH");
}
}
}
*Assessment report
[-]Failed tests
Test 4: Check No-Highest-Placement
Test 6: Check No-Highest-Placement
[-]Test 1: Check Conditions
[-]Summary of tests
*Note: All the test cases might not have same weightage
| 7 tests run/ 5 tests passed |
答案4
得分: 0
import java.util.*;
class Placement
{
public static void main (String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the no of students placed in CSE:");
int cse = sc.nextInt();
System.out.println("Enter the no of students placed in ECE:");
int ece = sc.nextInt();
System.out.println("Enter the no of students placed in MECH:");
int mech = sc.nextInt();
if(cse < 0 || ece < 0 || mech < 0)
System.out.print("Input is Invalid");
else if(cse == ece && ece == mech)
System.out.print("None of the department has got the highest placement");
else if (cse == ece && cse > mech)
System.out.print("Highest placement\n CSE\n ECE");
else if (ece == mech && cse < ece)
System.out.print("Highest placement\n ECE\n MECH");
else if (cse == mech && ece < mech)
System.out.print("Highest placement\n MECH\n CSE");
else if (cse > ece && cse > mech)
System.out.print("Highest placement\n CSE");
else if (ece > cse && ece > mech)
System.out.print("Highest placement\n ECE");
else if (mech > cse && mech > ece)
System.out.print("Highest placement\n MECH");
}
}
英文:
import java.util.*;
class Placement
{
public static void main (String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the no of students placed in CSE:");
int cse = sc.nextInt();
System.out.println("Enter the no of students placed in ECE:");
int ece = sc.nextInt();
System.out.println("Enter the no of students placed in MECH:");
int mech = sc.nextInt();
if(cse < 0 || ece < 0 || mech < 0)
System.out.print("Input is Invalid");
else if(cse == ece && ece == mech)
System.out.print("None of the department has got the highest placement");
else if (cse == ece && cse > mech)
System.out.print("Highest placement\n CSE\n ECE");
else if (ece == mech && cse < ece)
System.out.print("Highest placement\n ECE\n MECH");
else if (cse == mech && ece < mech)
System.out.print("Highest placement\n MECH\n CSE");
else if (cse > ece && cse > mech)
System.out.print("Highest placement\n CSE");
else if (ece > cse && ece > mech)
System.out.print("Highest placement\n ECE");
else if (mech > cse && mech > ece)
System.out.print("Highest placement\n MECH");
}
}
This will work perfectly.
答案5
得分: -1
import java.util.*;
public class Placement {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.printf("Enter the no of students placed in CSE:");
String str1 = sc.nextLine();
int i1 = Integer.parseInt(str1);
System.out.printf("Enter the no of students placed in ECE:");
String str2 = sc.nextLine();
int i2 = Integer.parseInt(str2);
System.out.printf("Enter the no of students placed in MECH:");
String str3 = sc.nextLine();
int i3 = Integer.parseInt(str3);
if (i1 == 0 && i2 == 0 && i3 == 0) {
System.out.println("None of the department has got the highest placement");
} else if (i1 == i2 && i2 == i3 && i3 == i2) {
System.out.println("None of the department has got the highest placement");
} else if (i1 < 0 || i2 < 0 || i3 < 0) {
System.out.println("Input is Invalid");
} else if (i1 == i2 && i1 != 0) {
System.out.println("Highest placement");
System.out.println("CSE");
System.out.println("ECE");
} else if (i1 == i3 && i1 != 0) {
System.out.println("Highest placement");
System.out.println("CSE");
System.out.println("MECH");
} else if (i2 == i3 && i2 != 0) {
System.out.println("Highest placement");
System.out.println("ECE");
System.out.println("MECH");
} else if (i1 > i2) {
if (i1 > i3) {
System.out.println("Highest placement");
System.out.println("CSE");
} else if (i1 == i3) {
System.out.println("Highest placement");
System.out.println("CSE");
System.out.println("MECH");
} else {
System.out.println("Highest placement");
System.out.println("MECH");
}
} else if (i2 > i1) {
if (i2 > i3) {
System.out.println("Highest placement");
System.out.println("ECE");
} else if (i2 == i3) {
System.out.println("Highest placement");
System.out.println("ECE");
System.out.println("MECH");
} else {
System.out.println("Highest placement");
System.out.println("MECH");
}
} else if (i1 != 0 && i2 != 0 && i3 != 0 && i1 == i2 && i2 == i3) {
System.out.println("Highest placement");
System.out.println("CSE");
System.out.println("ECE");
System.out.println("MECH");
} else {
System.out.println("MECH");
}
}
}
英文:
The code need to check if the number of placement is in zeroes
import java.util.*;
public class Placement {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.printf("Enter the no of students placed in CSE:");
String str1 = sc.nextLine();
int i1 = Integer.parseInt(str1);
System.out.printf("Enter the no of students placed in ECE:");
String str2 = sc.nextLine();
int i2 = Integer.parseInt(str2);
System.out.printf("Enter the no of students placed in MECH:");
String str3 = sc.nextLine();
int i3 = Integer.parseInt(str3);
if (i1 == 0 && i2 == 0 && i3 == 0) {
System.out.println("None of the department has got the highest placement");
} else if (i1 == i2 && i2 == i3 && i3 == i2) {
System.out.println("None of the department has got the highest placement");
} else if (i1 < 0 || i2 < 0 || i3 < 0) {
System.out.println("Input is Invalid");
} else if (i1 == i2 && i1 != 0) {
System.out.println("Highest placement");
System.out.println("CSE");
System.out.println("ECE");
} else if (i1 == i3 && i1 != 0) {
System.out.println("Highest placement");
System.out.println("CSE");
System.out.println("MECH");
} else if (i2 == i3 && i2 != 0) {
System.out.println("Highest placement");
System.out.println("ECE");
System.out.println("MECH");
} else if (i1 > i2) {
if (i1 > i3) {
System.out.println("Highest placement");
System.out.println("CSE");
} else if (i1 == i3) {
System.out.println("Highest placement");
System.out.println("CSE");
System.out.println("MECH");
} else {
System.out.println("Highest placement");
System.out.println("MECH");
}
} else if (i2 > i1) {
if (i2 > i3) {
System.out.println("Highest placement");
System.out.println("ECE");
} else if (i2 == i3) {
System.out.println("Highest placement");
System.out.println("ECE");
System.out.println("MECH");
} else {
System.out.println("Highest placement");
System.out.println("MECH");
}
} else if (i1 != 0 && i2 != 0 && i3 != 0 && i1 == i2 && i2 == i3) {
System.out.println("Highest placement");
System.out.println("CSE");
System.out.println("ECE");
System.out.println("MECH");
} else {
System.out.println("MECH");
}
}
专注分享java语言的经验与见解,让所有开发者获益!
评论