这是我的代码:
//method to rotate the picture
public static Picture modifyPicture (Picture p, int value)
{
// get width and height of the picture
int width = p.getWidth();
int height = p.getHeight();
System.out.println ("Picture has width of " + width +
" and height of " + height);
if (value == 1)
{
Picture p2 = new Picture (height, width);
int x = -1;
int y = -1;
for ( x = 0 ; x < width ; ++x )
{
for ( y = 0 ; y < height ; ++y )
{
// access the original pixel
Pixel pixel1 = p.getPixel (x, y);
Color c1 = pixel1.getColor();
// access the pixel to modify
int modifyXPos = (height-1)-y;
int modifyYPos = x;
Pixel pixel4 = p2.getPixel (modifyXPos, modifyYPos);
pixel4.setColor( c1 );
}
}
return p2;
}
else if (value == 2)
{
Picture p2 = new Picture ( width , height);
int x = -1;
int y = -1;
for ( x = 0 ; x < width ; ++x )
{
for ( y = 0 ; y < height ; ++y )
{
// access the original pixel
Pixel pixel1 = p.getPixel (x, y);
Color c1 = pixel1.getColor();
// access the pixel to modify
int modifyXPos = x;
int modifyYPos = (height-1) - y;
Pixel pixel4 = p2.getPixel (modifyXPos, modifyYPos);
pixel4.setColor( c1 );
}
}
return p2;
}
else
{
System.out.println ("Value out of range");
}
}
}//课程结束
因此,在倒数第二个分号处,我收到错误“缺少返回语句”,我明白为什么。我只是不知道我将如何解决它。在“if”语句之前重写图片 p2 等将是无用的,因为坐标必须改变,所以除此之外,我不知道如何在最后放置一个 return 语句。请帮助,并感谢您的时间和答案!