一个无法执行if语句问题
import java.util.*;class Square
{
int length,xTopLeft,yTopLeft,xBottomRight,yBottomRight;
int ID;
static int nextID;
Square(int xTopLeft,int yTopLeft,int length)
{
ID=nextID;nextID++;
this.length=length;this.xTopLeft=xTopLeft;this.yTopLeft=yTopLeft;
xBottomRight=xTopLeft+length;yBottomRight=yTopLeft-length;
}
void Move(int xOffset,int yOffset)
{
xTopLeft=xTopLeft+xOffset;
yTopLeft=yTopLeft+yOffset;
xBottomRight=xBottomRight+xOffset;
yBottomRight=yBottomRight+yOffset;
}
double Area()
{
return length*length;
}
double Perimeter()
{
return length*4;
}
}
public class SquareExp {
public static void main(String[] args)
{
Scanner scanner=new Scanner(System.in);
int length;
System.out.print("请输入你的边长:");
length=scanner.nextInt();
System.out.print("请输入你的左上角顶点x:");
int x=scanner.nextInt();
System.out.print("请输入你的左上角顶点y:");
int y=scanner.nextInt();
Square square=new Square(x,y,length);
System.out.println("输入: Y移动矩形 N不移动矩形");
String a=scanner.nextLine();
if(a=="Y")
{
System.out.print("请输入你移动的x距离:");
int xOffset=scanner.nextInt();
System.out.print("请输入你移动的y距离:");
int yOffset=scanner.nextInt();
square.Move(xOffset,yOffset);
}
else
{
}
System.out.println("边长="+length+" 周长="+square.Perimeter()+" 面积="+square.Area());
System.out.print("左上顶点的坐标为:("+square.xTopLeft+","+square.yTopLeft+") ");
System.out.println("右下顶点的坐标为:("+square.xBottomRight+","+square.yBottomRight+")");
}
}
为什么没办法执行if语句,用if(a.quealsIgnoreCase("Y"))也不可以