Home > Back-end >  Write a program, from the keyboard input the value of x, y value calculated output
Write a program, from the keyboard input the value of x, y value calculated output

Time:10-05

For bosses to help, the little brother just doesn't really understand,
Thank you bosses

CodePudding user response:

If the else

CodePudding user response:

JAVA program bosses will write?

CodePudding user response:

reference 1st floor weixin_44807526 response:
if the else

Write a JAVA's bosses will be?

CodePudding user response:

Which bosses can for example refer to thank??????

CodePudding user response:

import java.util.Scanner;

Public class Cal {

Public static void main (String [] args) {
Scanner sc=new Scanner(System.in);

}
}

CodePudding user response:

import java.util.Scanner;

Public class Cal {

Public static void main (String [] args) {
Scanner sc=new Scanner(System.in);//keyboard input
Int x=sc. NextInt ();//input integer
Int y;
If (x<1) y=x;
Else if (x<10) y=3 * x - 2;
The else y=4 * x;
System. The out. Println (x);


}
}

CodePudding user response:

refer to 6th floor Listener_yjt response:
import Java. Util. Scanner;

Public class Cal {

Public static void main (String [] args) {
Scanner sc=new Scanner(System.in);//keyboard input
Int x=sc. NextInt ();//input integer
Int y;
If (x<1) y=x;
Else if (x<10) y=3 * x - 2;
The else y=4 * x;
System. The out. Println (x);


}
}

Thank you for your big trouble you

CodePudding user response:

Give you a better point, upstairs there are three problems (also not a problem, but I more rigorous)
1, the requirement of the output is the value of y, his output is the value of x, here is the error of
2, not the tip on the input, and no error handling (if the input is not the integer, Fried program directly, I do the tips here, at the same time is not the integer can handle exceptions)
3, the last is the if the else, no matter whether the back is only a word, all want to play on the {} notation, it conforms to the coding standards, at the same time convenient read
Public static void main (String [] args) {

Scanner sc=new Scanner(System.in);//keyboard input
System. The out. Print (" please enter an integer: ");
Int x=0;
Try {
X=sc. NextInt ();//input integer
} the catch (Exception e) {
System. The out. Println (" you entered is not the integer ");
return;//end program
}
Int y;

If (x<1) {
Y=x;
} else if (x<10) {
Y=3 * x - 2;
} else {
Y=4 * x;
}
System. The out. Println (" y "+ y);


}

CodePudding user response:

refer to the eighth floor of luoyang city without fall Yang response:
give you a better point, upstairs there are three problems (also not a problem, but I more rigorous)
1, the requirement of the output is the value of y, his output is the value of x, here is the error of
2, not the tip on the input, and no error handling (if the input is not the integer, Fried program directly, I do the tips here, at the same time is not the integer can handle exceptions)
3, the last is the if the else, no matter whether the back is only a word, all want to play on the {} notation, it conforms to the coding standards, at the same time convenient read
Public static void main (String [] args) {

Scanner sc=new Scanner(System.in);//keyboard input
System. The out. Print (" please enter an integer: ");
Int x=0;
Try {
X=sc. NextInt ();//input integer
} the catch (Exception e) {
System. The out. Println (" you entered is not the integer ");
return;//end program
}
Int y;

If (x<1) {
Y=x;
} else if (x<10) {
Y=3 * x - 2;
} else {
Y=4 * x;
}
System. The out. Println (" y "+ y);


}

Thanks for elder brother!

CodePudding user response:

The
refer to 6th floor & lt; Span style="color: # 4788 c7" & gt; Listener_yjt & lt;/span> Response:
import Java. Util. Scanner;

Public class Cal {

Public static void main (String [] args) {
Scanner sc=new Scanner(System.in);//keyboard input
Int x=sc. NextInt ();//input integer
Int y;
If (x<1) y=x;
Else if (x<10) y=3 * x - 2;
The else y=4 * x;
System. The out. Println (x);


}
}
& lt; Br/& gt; Thank you big????????
  • Related