Home > Back-end >  Bosses, why this is wrong
Bosses, why this is wrong

Time:10-05

Scanner sc=new Scanner (System. In);
System. The out. Println (" please enter the first integer: ");
Int num1=sc. NextInt ();
System. The out. Println (" please enter an integer: ");
Int num2=sc. NextInt ();
Char num1 & gt; Num2? 'the first number is greater than the second number' : 'the first number is less than the second number;

CodePudding user response:

The last line of code change; String STR=num1 & gt; Num2?" The first number is greater than the second number ":" the first number is less than the second number ";
The results of the conditional operator is for? The first element of the back, or is the second element, you need to define a variable to receive the elements of the appropriate type, you write the String String should be used to receive, if you want to use char character receives, the single quotes can only write an element,
The basic content, more memory can convenient after learning, remember oh and junction post

CodePudding user response:

Scanner sc=new Scanner(System.in);
System. The out. Println (" please enter the first integer: ");
Int num1=sc. NextInt ();
System. The out. Println (" please enter an integer: ");
Int num2=sc. NextInt ();
String s=num1 & gt; Num2?" The first number is greater than the second number ":" the first number is less than the second number ";
System.out.println(s);