Java应用程序整数
我正试图用一个if语句创建我的第一个java应用程序,该语句将接受一个整数(e.x22),并找出它在相乘和相减(e.x2*2=4和2+2=4)时的和是否相等 虽然我不知道如何做if决定。有人能指出怎么做吗 谢谢你Java应用程序整数,java,Java,我正试图用一个if语句创建我的第一个java应用程序,该语句将接受一个整数(e.x22),并找出它在相乘和相减(e.x2*2=4和2+2=4)时的和是否相等 虽然我不知道如何做if决定。有人能指出怎么做吗 谢谢你 package 1; import java.util.Scanner; public class 1 { public static void main(String[] args) { Scanner input = new Scanner(
package 1;
import java.util.Scanner;
public class 1
{
public static void main(String[] args)
{
Scanner input = new Scanner( System.in );
int x;
int y;
System.out.print( "Enter a number from 10 to 99: " );
x = input.nextInt();
if ( x >= 10 && x <= 99 )
{
x= x % 10;
x= x / 10;
}
else
{
System.out.println( "you must enter a number from 10 to 99" );
}
}
}
包1;
导入java.util.Scanner;
公共一级
{
公共静态void main(字符串[]args)
{
扫描仪输入=新扫描仪(System.in);
int x;
int-y;
System.out.print(“输入10到99之间的数字:”);
x=input.nextInt();
如果(x>=10&&x您只需要将它们分配给不同的变量并检查条件
if (x >= 10 && x <= 99) {
int first = x / 10; // Take out the first digit and assign it to a variable first
int second = x % 10; // Take out the second digit and assign it to a variable second
if (first * second == first + second) { // Check for your condition, which you mentioned in your question
System.out.println("Yep, they match the condition"); // If it satisfies the condition
} else {
System.out.println("Nope, they don't match the condition"); // If it doesn't satisfy the condition
}
}
如果(x>=10&&x尝试
import java.util.Scanner;
公共一级{
公共静态void main(字符串[]args){
扫描仪输入=新扫描仪(System.in);
int x;
int-y;
System.out.print(“输入10到99之间的数字:”);
x=input.nextInt();
如果(x>=10&&x从任何Java教程中的标识符和变量开始。如果(x==y){这个条件完全错误。请重新阅读问题。@R.J是的,您的答案是正确的+1,感谢您指出,我们已经更新了代码
import java.util.Scanner;
public class One {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int x;
int y;
System.out.print("Enter a number from 10 to 99: ");
x = input.nextInt();
if (x >= 10 && x <= 99) {
y = x % 10;
x = x/10 ;
if(x* y== x+ y)){
System.out.println("Sum and product are equal" );
}
else
System.out.println("Sum and product are not equal" );
} else {
System.out.println("you must enter a number from 10 to 99");
}
input.close();
}
}