java吧 关注:1,257,654贴子:12,752,194
  • 7回复贴,共1

初学小白求教

只看楼主收藏回复

老师之前在课上让我们简单的写了一个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颠倒过来输出,可以做到么?求代码,我想学习一下。


IP属地:北京1楼2016-09-19 00:38回复
    据我所知,好像没有倒过来的方法。 string方法没有。 你可以俩个都写一个里面,if else


    来自iPhone客户端2楼2016-09-19 01:07
    收起回复
      广告
      立即查看
      正反斜杠单独存,通过输入参数bottom和top进行判断输出


      IP属地:四川来自Android客户端3楼2016-09-19 09:08
      收起回复
        小白想学我可以送你个全套视频


        IP属地:江苏5楼2016-09-19 11:34
        收起回复