A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© e咕噜 中级黑马   /  2015-7-11 21:56  /  428 人查看  /  7 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文


山 汉
阻 宫
绝 彻
秦 夜
帝 捧
船 金
    盘            求这种方式的打印方法,

7 个回复

倒序浏览
kao,这也可以
回复 使用道具 举报
class Demo
{
        public static void main(String[] args)
        {
                String[] arr={"涛","山","阻","绝","秦","帝","船"};
                String[] arr1={"汉","宫","彻","夜","捧","金","盘"};
                for (int x=0;x<arr.length ;x++ )
                {
                        System.out.println(arr[x]+" "+arr1[x]);
                       

                }

        }
}
回复 使用道具 举报 1 0
想了半天,还是想不出来。这个应该..........
回复 使用道具 举报
要考虑一下
回复 使用道具 举报
代码如下:
  1. class  Demo3
  2. {
  3.         public static void main(String[] args)
  4.         {
  5.        char [] str="涛山汉阻宫绝彻秦夜帝捧船金盘".toCharArray();
  6.            int i=0;
  7.            while(i<str.length)
  8.                 {
  9.                    if(i==0)//涛  
  10.                         {
  11.               System.out.print(str[i]+"  ");
  12.                           System.out.println();
  13.                           i+=1;
  14.                         }
  15.                      else if(i>0&&i<str.length-1)//山 汉
  16.                         {
  17.               System.out.print(str[i]+" "+str[i+1]);
  18.                           i+=2;
  19.               System.out.println();
  20.                         }
  21.                         else if(i==str.length-1)//   盘
  22.                         {
  23.                                 //i-=1;
  24.                System.out.print("   "+str[i]);
  25.                            i+=1;
  26.                         }
  27.          
  28.                 }
  29.         }
  30. }
复制代码



回复 使用道具 举报
黑马和大灰狼 来自手机 中级黑马 2015-7-12 01:00:03
7#
双层for循环哦
回复 使用道具 举报
一楼写的很好
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马