Java 设计类
发布网友
发布时间:2022-04-29 01:12
我来回答
共2个回答
热心网友
时间:2022-06-27 06:15
//由于我不太了解你的问题到底是要求达到什么目的,我只是简单满足你上面的两个要求写了一下代码。如果还有什么要求不能满足的,请把问题写详细点。谢谢!
public class Print
{
public Print(int n)
{
for (int i = 1 ; i <= n/2; i++)
{
System.out.print(i + " ") ;
}
System.out.println();
}
public Print(int from , int end , int n)
{
for (int i = from ; i <= end ; i+= n)
{
System.out.print(i+" ");
}
System.out.println();
}
public static void main(String[] args)
{
new Print(10) ;
new Print(3,15,3);
}
}
//输出结果如下:
1 2 3 4 5
3 6 9 12 15
热心网友
时间:2022-06-27 06:16
public class Print
{
public Print(int n)
{
for (int i = 1 ; i <= n/2; i++)
{
System.out.print(i + " ") ;
}
System.out.println();
}
public Print(int from , int end , int n)
{
for (int i = from ; i <= end ; i+= n)
{
System.out.print(i+" ");
}
System.out.println();
}
public static void main(String[] args)
{
new Print(10) ;
new Print(3,15,3);
}
}