老师之前在课上让我们简单的写了一个class,就是输出了几个由 - / \等符号组成的图形(字符串),代码如下
public class huatu
{
public static void main(String[] args)
{
egg();
teacup();
stop();
hat();
desk();
}
public static void egg()
{
eggtop();
eggbottom();
System.out.println();
}
public static void teacup()
{
eggbottom();
line();
System.out.println();
}
public static void stop()
{
eggtop();
System.out.println("| STOP |");
eggbottom();
System.out.println();
}
public static void hat()
{
eggtop();
line();
System.out.println();
System.out.println();
}
public static void desk()
{
eggbottom();
eggtop();
}
public static void eggtop()
{
System.out.println(" ---- ");
System.out.println(" / \\ ");
System.out.println("/ \\");
}
public static void eggbottom()
{
System.out.println("\\ /");
System.out.println(" \\ /");
System.out.println(" ---- ");
}
public static void line()
{
System.out.println("+-----+");
}
}
现在我考虑,其实eggbottom和eggtop其实就是同一个图形上下颠倒,可否省略掉一个函数,比如不要eggbottom函数,而通过某个参数设置条件,然后当需要eggbottom的时候用这个参数控制eggtop,使eggtop颠倒过来输出,可以做到么?求代码,我想学习一下。
public class huatu
{
public static void main(String[] args)
{
egg();
teacup();
stop();
hat();
desk();
}
public static void egg()
{
eggtop();
eggbottom();
System.out.println();
}
public static void teacup()
{
eggbottom();
line();
System.out.println();
}
public static void stop()
{
eggtop();
System.out.println("| STOP |");
eggbottom();
System.out.println();
}
public static void hat()
{
eggtop();
line();
System.out.println();
System.out.println();
}
public static void desk()
{
eggbottom();
eggtop();
}
public static void eggtop()
{
System.out.println(" ---- ");
System.out.println(" / \\ ");
System.out.println("/ \\");
}
public static void eggbottom()
{
System.out.println("\\ /");
System.out.println(" \\ /");
System.out.println(" ---- ");
}
public static void line()
{
System.out.println("+-----+");
}
}
现在我考虑,其实eggbottom和eggtop其实就是同一个图形上下颠倒,可否省略掉一个函数,比如不要eggbottom函数,而通过某个参数设置条件,然后当需要eggbottom的时候用这个参数控制eggtop,使eggtop颠倒过来输出,可以做到么?求代码,我想学习一下。