用Java写出程序,求高手求助,2题
答案:1 悬赏:50 手机版
解决时间 2021-04-07 07:05
- 提问者网友:未信
- 2021-04-06 23:01
用Java写出程序,求高手求助,2题
最佳答案
- 五星知识达人网友:廢物販賣機
- 2021-04-07 00:35
// 第一题
public class Kyo
{
public static void main(String[] args)
{
String[] week = "日一二三四五六".split("(?!\b)");
for(int i = 0; i < week.length; i++)
{
for(int j = i + 1; j < week.length; j++)
{
for(int k = j + 1; k < week.length; k++)
{
System.out.println("星期" + week[i] + ", 星期" + week[j] + ", 星期" + week[k]);
}
}
}
}
}
// 第二题
public class Rect
{
private double width;
private double height;
public Rect()
{}
public Rect(double width)
{
this.width = width;
}
public Rect(double width, double height)
{
this.width = width;
this.height = height;
}
public double area()
{
return width * height;
}
public double perimeter()
{
return 2 * (width + height);
}
public void print()
{
for(int i = 0; i < height; i++)
{
for(int j = 0; j < width; j++)
{
if(i > 0 && i < height - 1 && j > 0 && j < width - 1)
{
System.out.print(" ");
}
else
{
System.out.print("*");
}
}
System.out.println();
}
}
public static void main(String[] args)
{
Rect rect1 = new Rect();
rect1.print();
Rect rect2 = new Rect(6);
rect2.print();
Rect rect3 = new Rect(6, 3);
rect3.print();
}
}
public class Kyo
{
public static void main(String[] args)
{
String[] week = "日一二三四五六".split("(?!\b)");
for(int i = 0; i < week.length; i++)
{
for(int j = i + 1; j < week.length; j++)
{
for(int k = j + 1; k < week.length; k++)
{
System.out.println("星期" + week[i] + ", 星期" + week[j] + ", 星期" + week[k]);
}
}
}
}
}
// 第二题
public class Rect
{
private double width;
private double height;
public Rect()
{}
public Rect(double width)
{
this.width = width;
}
public Rect(double width, double height)
{
this.width = width;
this.height = height;
}
public double area()
{
return width * height;
}
public double perimeter()
{
return 2 * (width + height);
}
public void print()
{
for(int i = 0; i < height; i++)
{
for(int j = 0; j < width; j++)
{
if(i > 0 && i < height - 1 && j > 0 && j < width - 1)
{
System.out.print(" ");
}
else
{
System.out.print("*");
}
}
System.out.println();
}
}
public static void main(String[] args)
{
Rect rect1 = new Rect();
rect1.print();
Rect rect2 = new Rect(6);
rect2.print();
Rect rect3 = new Rect(6, 3);
rect3.print();
}
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯