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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 王震阳老师 金牌黑马   /  2014-7-4 16:55  /  15766 人查看  /  283 人回复  /   2 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 就业指导-王震阳老师 于 2014-8-18 11:09 编辑

活动目的:练习javaSE知识,本次侧重练习Java的控制语句部分

活动奖励:最高3个技术分

结束时间:2014年7月7日,过期提交可能获取不到技术分!

代码提交要求:将自己的源代码压缩然后提交,提交的时候设置为管理员权限,以其他方式提交的答案无效。上交源码的时候不需要将整个工程项目压缩,只需将用到的源文件压缩即可。

题目类型:控制语句操作,打印图案。

题目:老规矩,回帖领题
游客,如果您要查看本帖隐藏内容请回复
更多技术分活动:
【阳哥专栏】技术分活动第12期
http://bbs.itheima.com/thread-138162-1-1.html

【阳哥专栏】技术分活动第11期
http://bbs.itheima.com/thread-137632-1-1.html
【阳哥专栏】技术分活动第10期
http://bbs.itheima.com/thread-136866-1-1.html
【阳哥专栏】技术分活动第9期
http://bbs.itheima.com/thread-136465-1-1.html
【阳哥专栏】技术分活动第8期
http://bbs.itheima.com/thread-135781-1-1.html
【阳哥专栏】技术分活动第7期
http://bbs.itheima.com/thread-134321-1-1.html
【阳哥专栏】周末技术分活动第6期
http://bbs.itheima.com/thread-132893-1-1.html
【阳哥专栏】周末技术分活动第5期
http://bbs.itheima.com/thread-129859-1-1.html
【阳哥专栏】周末技术分活动第4期
http://bbs.itheima.com/thread-128854-1-1.html
【阳哥专栏】周末技术分活动第3期
http://bbs.itheima.com/thread-127326-1-1.html
【阳哥专栏】周末技术分活动第2期
http://bbs.itheima.com/thread-125800-1-1.html
【阳哥专栏】周末技术分派送活动第1期
http://bbs.itheima.com/thread-123979-1-1.html

283 个回复

倒序浏览
家进 发表于 2014-9-19 09:56
臣接旨,保证完成任务

好吧,你赢了
回复 使用道具 举报

你一定仔细把题目吃透。
回复 使用道具 举报
mmppp 发表于 2014-12-6 15:51
Exam3 搞定  上传  请检查
  1. class  Exam3
  2. {
  3.         public static void Shu()
  4.         {
  5.                 for(int x=0;x<6;x++)
  6.                 {
  7.                         for(int y=0;y<5-x;y++)
  8.                         {
  9.                                 System.out.print(" ");
  10.                         }
  11.                         for(int z=0;z<2*x+1;z++)
  12.                         {
  13.                                 System.out.print("*");
  14.                         }
  15.                         System.out.println();
  16.                 }
  17.                 for(int x=0;x<5;x++)
  18.                 {
  19.                         for(int y=0;y<x+1;y++)
  20.                         {
  21.                                 System.out.print(" ");
  22.                         }
  23.                         for(int z=0;z<9-2*x;z++)
  24.                         {
  25.                                 System.out.print("*");
  26.                         }
  27.                         System.out.println();
  28.                 }
  29.         }
  30.         public static void Heng()
  31.         {
  32.                
  33.                 for(int x=0;x<6;x++)
  34.                 {
  35.                         for(int y=0;y<10-2*x;y++)
  36.                         {
  37.                                 System.out.print(" ");
  38.                         }
  39.                         for(int z=0;z<2*x+1;z++)
  40.                         {
  41.                                 System.out.print("* ");
  42.                         }
  43.                         System.out.println();
  44.                 }
  45.                 for(int x=0;x<5;x++)
  46.                 {
  47.                         for(int y=0;y<2*x+2;y++)
  48.                         {
  49.                                 System.out.print(" ");
  50.                         }
  51.                         for(int z=0;z<9-2*x;z++)
  52.                         {
  53.                                 System.out.print("* ");
  54.                         }
  55.                         System.out.println();
  56.                 }
  57.        
  58.         }
  59.         public static void main(String[] args)
  60.         {
  61.                 int a = 3;
  62.                 if(a%4==1||a%4==3)
  63.                 {
  64.                         System.out.println("旋转的度数为:"+a*90+"度");
  65.                         System.out.println("图形为");
  66.                         Heng();
  67.                         System.out.println();
  68.                         System.out.println();
  69.                 }
  70.                 else
  71.                 {
  72.                         System.out.println("旋转的度数为:"+a*90+"度");
  73.                         System.out.println("图形为");
  74.                         Shu();
  75.                 }
  76.                
  77.                
  78.                
  79.         }
  80. }
复制代码

不错。
回复 使用道具 举报
陈宁 发表于 2014-12-8 09:09
已传,老师请验收!
  1. package day13;
  2. import java.util.Scanner;
  3. /*
  4.      *
  5.     ***
  6.    *****
  7.   *******
  8. *********
  9. ***********
  10. *********
  11.   *******
  12.    *****
  13.     ***
  14.      *
  15. */
  16. public class TheThirdExam {
  17.         public static void main(String[] args) {
  18.                 Scanner s=new Scanner(System.in);
  19.                 System.out.println("请输入一个数:");
  20.                 int input=s.nextInt();
  21.                
  22.                 //正三角
  23.                 int count=0;
  24.                 for(int a=1;a<=input;a++){
  25.                         for(int b=0;b<=input+count;b++){
  26.                                 if(b<=input-a){
  27.                                         System.out.print(" ");
  28.                                 }else{
  29.                                         System.out.print("*");
  30.                                 }
  31.                         }
  32.                         System.out.println();
  33.                         count++;
  34.                 }
  35.                
  36.                 //倒三角
  37.                 for(int a=1;a<input;a++){
  38.                         for(int b=1;b<input+count;b++){
  39.                                 if(b<=a+1){
  40.                                         System.out.print(" ");
  41.                                 }else{
  42.                                         System.out.print("*");
  43.                                 }       
  44.                         }
  45.                         System.out.println();
  46.                         count--;
  47.                 }
  48.         }

  49. }
复制代码

不错。
回复 使用道具 举报
佛说 发表于 2014-12-8 20:28
老师,我又来领题了

好的,老面孔了。
回复 使用道具 举报
wangzheng406 发表于 2014-12-10 02:04
这题用二维数组,挺好玩的。

不错。
  1. import java.io.*;

  2. class HeimaDemo{
  3.         public static void main (String []args) throws IOException{
  4.                 BufferedReader br = new BufferedReader(
  5.                                                                 new InputStreamReader(System.in) );
  6.                 int x = 0 ;
  7.                 System.out.println("请输入一个大于2的数字,初始化图形");
  8.                 while(true){
  9.                         String line = br.readLine();
  10.                          x = Integer.parseInt(line);
  11.                                 if(x>2){
  12.                                         break;
  13.                                 }
  14.                                 System.out.println("请输入一个大于2的数字!");
  15.                 }
  16.                 char [][]arr = ready(x);
  17.                 print(arr);
  18.                 int y = 0 ;
  19.                 System.out.println("请输入一个大于0的数字,图形将会翻转。输入exit退出。");
  20.                 while(true){
  21.                         String line = br.readLine();
  22.                           boolean b=line.matches("[0-9]*");
  23.                           if(b) {
  24.                                   y=Integer.parseInt(line);

  25.                                                 for(y=y%4;y>0 ;y--){
  26.                                                         arr = spin(arr);
  27.                                                 }
  28.                                                 print(arr);

  29.                                         System.out.println("请输入一个大于0的数字!输入exit退出");         
  30.                           }
  31.                           else{
  32.                                   if(line.equals("exit")){
  33.                                           break;
  34.                                   }
  35.                                   else
  36.                                   System.out.println("输入的数字有误!");
  37.                           }

  38.                 }
  39.         }
  40.        
  41.         public static char[][] ready(int x){
  42.                 char [][]arr = new char[x][x];
  43.                 for( int n = 0;n < x ; n++ ){
  44.                         for( int m = 0;m < x ; m++ ){

  45.                                 if(n+m>=(x-1)/2 && n+m<= x/2+x-1 && m-n<=x/2 && n-m<=x/2 ){
  46.                                         arr[n][m] = '*';
  47.                                 }
  48.                         }
  49.                 }
  50.                 arr[0][(x-1)/2-1] = 'O';
  51.                 arr[0][x/2+1] = 'O';
  52.                 return arr;
  53.         }
  54.        
  55.         public static void print(char[][] arr){
  56.                 int x =arr.length;
  57.                 for( int n = 0;n < x ; n++ ){
  58.                         for( int m = 0;m < x ; m++ ){
  59.                                 System.out.print(arr[n][m]);
  60.                         }
  61.                         System.out.println();
  62.                 }
  63.         }       
  64.        
  65.         public static char[][] spin(char[][] arr){
  66.                 int x =arr.length;
  67.                
  68.                 char[][] temp = new char[x][x];
  69.                 for( int n = 0;n < x ; n++ ){
  70.                         for( int m = 0;m < x ; m++ ){
  71.                                 temp[m][x-n-1] = arr[n][m] ;
  72.                         }
  73.                 }
  74.                 return temp ;
  75.         }       
  76. }
复制代码
回复 使用道具 举报
wangzheng406 发表于 2014-12-10 02:04
这题用二维数组,挺好玩的。

不错:
  1. import java.io.*;

  2. class HeimaDemo{
  3.         public static void main (String []args) throws IOException{
  4.                 BufferedReader br = new BufferedReader(
  5.                                                                 new InputStreamReader(System.in) );
  6.                 int x = 0 ;
  7.                 System.out.println("请输入一个大于2的数字,初始化图形");
  8.                 while(true){
  9.                         String line = br.readLine();
  10.                          x = Integer.parseInt(line);
  11.                                 if(x>2){
  12.                                         break;
  13.                                 }
  14.                                 System.out.println("请输入一个大于2的数字!");
  15.                 }
  16.                 char [][]arr = ready(x);
  17.                 print(arr);
  18.                 int y = 0 ;
  19.                 System.out.println("请输入一个大于0的数字,图形将会翻转。输入exit退出。");
  20.                 while(true){
  21.                         String line = br.readLine();
  22.                           boolean b=line.matches("[0-9]*");
  23.                           if(b) {
  24.                                   y=Integer.parseInt(line);

  25.                                                 for(y=y%4;y>0 ;y--){
  26.                                                         arr = spin(arr);
  27.                                                 }
  28.                                                 print(arr);

  29.                                         System.out.println("请输入一个大于0的数字!输入exit退出");         
  30.                           }
  31.                           else{
  32.                                   if(line.equals("exit")){
  33.                                           break;
  34.                                   }
  35.                                   else
  36.                                   System.out.println("输入的数字有误!");
  37.                           }

  38.                 }
  39.         }
  40.        
  41.         public static char[][] ready(int x){
  42.                 char [][]arr = new char[x][x];
  43.                 for( int n = 0;n < x ; n++ ){
  44.                         for( int m = 0;m < x ; m++ ){

  45.                                 if(n+m>=(x-1)/2 && n+m<= x/2+x-1 && m-n<=x/2 && n-m<=x/2 ){
  46.                                         arr[n][m] = '*';
  47.                                 }
  48.                         }
  49.                 }
  50.                 arr[0][(x-1)/2-1] = 'O';
  51.                 arr[0][x/2+1] = 'O';
  52.                 return arr;
  53.         }
  54.        
  55.         public static void print(char[][] arr){
  56.                 int x =arr.length;
  57.                 for( int n = 0;n < x ; n++ ){
  58.                         for( int m = 0;m < x ; m++ ){
  59.                                 System.out.print(arr[n][m]);
  60.                         }
  61.                         System.out.println();
  62.                 }
  63.         }       
  64.        
  65.         public static char[][] spin(char[][] arr){
  66.                 int x =arr.length;
  67.                
  68.                 char[][] temp = new char[x][x];
  69.                 for( int n = 0;n < x ; n++ ){
  70.                         for( int m = 0;m < x ; m++ ){
  71.                                 temp[m][x-n-1] = arr[n][m] ;
  72.                         }
  73.                 }
  74.                 return temp ;
  75.         }       
  76. }
复制代码
回复 使用道具 举报
0_TNT_0 发表于 2014-12-13 23:30
老师题目答完了,请阅,谢谢!!!

再次再提交答案一定把截图也提交了。
回复 使用道具 举报
Little_Pea 发表于 2014-12-15 15:29
有阳哥的鼓励,我会越挫越勇的!加油!!!

哈哈,要相信自己,努力肯定会有回报。
回复 使用道具 举报

任性给分:
  1. package Test;
  2. import java.util.Scanner;

  3. /**@program打印菱形
  4. * @author ad祁祯祥
  5. *
  6. */
  7. public class Diamond {

  8.         /**
  9.          * @param args
  10.          */
  11.         public static void main(String[] args) {
  12.                 // TODO Auto-generated method stub
  13.                 Scanner sc=new Scanner(System.in);
  14.                 for(int a=0;a==a;a++){
  15.                         System.out.println("请输入要多少行:");
  16.                  int size = sc.nextInt();//定义有多少行
  17.        /* 打印出来的是奇数行菱形
  18.         * if(size%2==0){       
  19.                 size=size/2;
  20.         }else{
  21.                 size=(size+1)/2;
  22.         }*/
  23.                 for (int i = 1; i <= size; i++) {//外层循环控制趟数
  24.                         for (int j = i; j < size; j++) {//这一层控制空白的地方
  25.                                 System.out.print(" ");
  26.                         }

  27.                         for (int k = 1; k <= 2 * i - 1; k++) {//这层控制星星的数量
  28.                                 System.out.print("*");
  29.                         }

  30.                         System.out.println();
  31.                
  32.                 }
  33.            //反方向打印图形,即做图形的下半部分
  34.                 for (int i = size - 1; i >= 1; i--) {
  35.                                 for (int j = 1; j <= size - i; j++) {
  36.                                         System.out.print(" ");
  37.                                 }
  38.                        
  39.                                 for (int k = 2 * i - 1; k > 0; k--) {
  40.                                 System.out.print("*");
  41.                                 }
  42.                        
  43.                         System.out.println();
  44.                         }
  45.                 }
  46.         }

  47. }
复制代码
回复 使用道具 举报
祁祯祥 发表于 2014-12-16 23:33
谢谢阳哥,下次我会注意,别的题目还没学到,暂时不会,过段时间我来包场,所有题目 ...

哈哈,这倒不至于包场。我做技术分活动的一个目的就是让大家重视基础,在我眼里基础是最重要的。
回复 使用道具 举报

很好:
  1. import java.util.Scanner;


  2. public class Demo3 {

  3.         /**
  4. * 打印如下图案:要求,通过输入不同的参数(比如1、2、3、4...N)该图案可以90°*N的倍数进行顺时针旋转。不需要图形化界面,在控制台中输出即可。注意:图中的“I”为占位符,真实的图形不应该有此符号。
  5.      *
  6.     ***
  7.    *****
  8.   *******
  9. *********
  10. ***********
  11. *********
  12.   *******
  13.    *****
  14.     ***
  15.      *
  16. */
  17.         public static void main(String[] args) {
  18.                 // TODO Auto-generated method stub
  19.           int n=3;
  20.           Scanner sc=new Scanner(System.in);
  21.           int l=sc.nextInt();
  22.           int k=l%4;
  23.           switch(k){
  24.           case 1:
  25.                   show1(n);
  26.                   break;
  27.           case 2:
  28.                   show2(n);
  29.                   break;
  30.           case 3:
  31.                   show1(n);
  32.                   break;
  33.           case 0:
  34.                   show2(n);
  35.                   break;
  36.           }
  37.         }       
  38.         public static void show1(int n){
  39.                 for(int i = 0; i < n - 1; i++)  
  40.         {  
  41.             for(int x = i + 1; x < n; x++)  
  42.             {  
  43.                 System.out.print(" ");  
  44.             }  
  45.             for(int y = 0; y < (i + 1) * 2 - 1; y++)  
  46.             {  
  47.                 System.out.print("*");  
  48.             }  
  49.             System.out.println();  
  50.         }  
  51.         for(int i = 0; i < n; i++)  
  52.         {  
  53.             for(int x = 0; x < i; x++)  
  54.             {  
  55.                 System.out.print(" ");  
  56.             }  
  57.             for(int y = i; y < 2 * n - i - 1; y++)  
  58.             {  
  59.                 System.out.print("*");  
  60.             }  
  61.             System.out.println();  
  62.         }  
  63.    }
  64.         public static void show2(int n){
  65.                 for(int i = 0; i < n - 1; i++)  
  66.         {  
  67.             for(int x = i + 1; x < n; x++)  
  68.             {  
  69.                 System.out.print("   ");  
  70.             }  
  71.             for(int y = 0; y < (i + 1) * 2 - 1; y++)  
  72.             {  
  73.                 System.out.print(" * ");  
  74.             }  
  75.             System.out.println();  
  76.         }  
  77.         for(int i = 0; i < n; i++)  
  78.         {  
  79.             for(int x = 0; x < i; x++)  
  80.             {  
  81.                 System.out.print("   ");  
  82.             }  
  83.             for(int y = i; y < 2 * n - i - 1; y++)  
  84.             {  
  85.                 System.out.print(" * ");  
  86.             }  
  87.             System.out.println();  
  88.         }  
  89.         }
  90.        
  91. }

复制代码
回复 使用道具 举报
风祭将o 发表于 2014-12-24 13:27
我做出来了,不过因为控制台的行距是固定的,无法体现旋转后菱形变扁的情况。
我还有一个问题,就是在用rep ...

赞一个:
  1. package gaoxin;

  2. import java.util.Scanner;

  3. public class SpinRhombus {

  4.         public static void main(String[] args) {
  5.                 // 定义一个输入流来录入键盘信息,由于每次只读一个字节,所以我就使用了scanner
  6.                 Scanner in = new Scanner(System.in);
  7.                 int num = 0;
  8.                 while ((num = in.nextInt()) != 0) {
  9.                         // 根据输入参数打印不同角度的菱形,直到输入0结束
  10.                         printRhombus(num);
  11.                 }
  12.                 //关闭流
  13.                 in.close();
  14.         }

  15.         public static void printRhombus(int num) {
  16.                 // 由于菱形任意旋转180度的倍数都是原图形,所以我定义了两种情况:1,原图形没旋转的 2,旋转了90度的
  17.                 // 当输入的数字是2的倍数时(即180度*n),都是原图形
  18.                 if (num % 2 == 0) {
  19.                         // 我用两个for循环来打印菱形,这是上半部分
  20.                         // 定义一开始时输出的内容space
  21.                         String space = "   *";
  22.                         for (int x = 1; x < 5; x++) {
  23.                                 System.out.println(space);
  24.                                 // 每打印一次,都让space去掉前面的一个空格
  25.                                 space = space.substring(1);
  26.                                 // 再加上多出来的**
  27.                                 space = space + "**";
  28.                         }
  29.                         // 下半部分
  30.                         // 由于以上的循环多打印了一个*,我把它去掉
  31.                         space = space.substring(1);
  32.                         for (int x = 1; x < 4; x++) {
  33.                                 // 为了打印下半部分星星逐次递减的情况, 每次都把第一个*用空格替代
  34.                                 space = space.replaceFirst("\\*", " ");
  35.                                 // 再去掉末尾的一个*
  36.                                 space = space.substring(0, space.length() - 1);
  37.                                 // 打印一行
  38.                                 System.out.println(space);
  39.                         }
  40.                 }

  41.                 // 旋转了90度的菱形,代码原理同上,只是星星间空隙变大
  42.                 else {
  43.                         String space = "       *";
  44.                         for (int x = 1; x < 5; x++) {
  45.                                 System.out.println(space);
  46.                                 space = space.substring(2);
  47.                                 space = space + " * *";
  48.                         }
  49.                         space = space.substring(2);
  50.                         for (int x = 1; x < 4; x++) {
  51.                                 space = space.replaceFirst("\\*", " ");
  52.                                 space = space.substring(0, space.length() - 2);
  53.                                 System.out.println(space);
  54.                         }
  55.                 }

  56.         }
  57. }
复制代码
回复 使用道具 举报
陈建民 发表于 2015-4-22 21:35
阳哥好好,i love you

哈哈,你这是干嘛
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马