📣 黑五价提前开抢|VIP一年通行证5折,蓝莓、Offer多多同步特惠
查看: 8368| 回复: 26
跳转到指定楼层
上一主题 下一主题
收起左侧

[CS61B_Spring 2015] HW0 加分讨论帖

全局:
公开课
学校名称: Berkeley
Unit号: 14
开课时间: 2015-05-25
课程全名: CS61B Data Structures
平台: 其他

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x
本帖最后由 hurricane_e 于 2015-5-27 03:01 编辑

如题。
考虑到课程的难度和作业量,以及@ AveMaleficum 斑竹的建议,我们的加分规则是:HW和Project加1学分,Labs和Discussion各加20米。
提交作业可以贴上运行成功截图或者代码~


上一篇:伯克利 CS 61b 资料分享(slice 和 视频 )
下一篇:[CS61B_Spring 2015] Discussion1-Intro to Java
推荐
diehard 2015-6-22 16:54:47 | 只看该作者
全局:
1a
  1. public class DrawATriangle {
  2.         public static void main(String [] args) {

  3.                 int row = 0;
  4.                 int SIZE = 5;
  5.                 while (row < SIZE) {
  6.                         int col = 0;
  7.                         while (col <= row) {
  8.                                 System.out.print('*');
  9.                                 col = col + 1;
  10.                         }
  11.                         System.out.println();
  12.                         row = row + 1;
  13.                 }       
  14.        
  15.         }
  16. }
复制代码
1b
  1. public class DrawTriangle {
  2.    public static void drawTriangle(int N) {
  3.       int row = 0;
  4.                 int SIZE = N;
  5.                 while (row < SIZE) {
  6.                         int col = 0;
  7.                         while (col <= row) {
  8.                                 System.out.print('*');
  9.                                 col = col + 1;
  10.                         }
  11.          System.out.println();
  12.          row = row + 1;
  13.       }
  14.    }
  15.    public static void main(String[] args) {
  16.       drawTriangle(20);
  17.       
  18.    }
  19. }
复制代码
2
  1. public class exercise2 {
  2.    public static int max(int[] m) {
  3.       int max = m[0];
  4.       for(int i=0; i < m.length; i++) {
  5.          if (m[i] > max) {
  6.             max = m[i];
  7.          }
  8.       }
  9.       return max;
  10.    }
  11.    public static void main(String[] args) {
  12.       int[] numbers = new int[]{9, 2, 15, 2, 22, 10, 6};
  13.       System.out.println(max(numbers));
  14.    }
  15. }
复制代码

点评

请问这个框框效果是怎么做到的啊,求教。。  发表于 2015-7-10 12:20

评分

参与人数 1大米 +10 收起 理由
忆梦前尘 + 10 回答的很好!

查看全部评分

回复

使用道具 举报

推荐
baiery 2015-5-26 14:32:03 | 只看该作者
全局:
结果都对就不放结果截图了
1a.
// draw a triangle
public class HW0_1a {
       
        public static void main(String[] args) {
                // TODO Auto-generated method stub
                int row = 0;
                int col = 0;
                while (row < 5){
                        while (col < row+1){
                                if (col == row){
                                System.out.println("*");
                                }else{
                                        System.out.print("*");
                                }
                                col++;
                        }
                        col = 0;
                        row++;
                }
        }

}

1b.
// draw a triangle
public class HW0_1a {
       
        public static void main(String[] args) {
                // TODO Auto-generated method stub
                int row = 0;
                int col = 0;
                while (row < 5){
                        while (col < row+1){
                                if (col == row){
                                System.out.println("*");
                                }else{
                                        System.out.print("*");
                                }
                                col++;
                        }
                        col = 0;
                        row++;
                }
        }

}

2.
public class HW0_2 {
        public static int max(int[] m) {
                int k = 0;
                int temp = m[0];
                while (k < m.length-1){
                        if (m[k+1] > temp){
                                temp = m[k+1];
                        }
                        k++;
                }
               return temp;
           }
        public static void main(String[] args) {
                // TODO Auto-generated method stub
                int[] numbers = new int[]{9, 2, 15, 2, 22, 10, 6};
                System.out.println(max(numbers));
        }

}

刚开始编程,经验不够,感觉自己写的有些冗长,希望有经验的大神多多贴一下简洁效率高的代码参考参考!谢谢!
回复

使用道具 举报

推荐
whosays 2015-5-26 06:54:03 | 只看该作者
全局:
很丢人地发现自己不会发图片……本来截图效果最好的。。。就发下代码吧,这门课应该不存在honor code的问题?

1. 五阶StarTriangle
public class StarTriangle {
        public static void main(String[] args) {
                int col = 0;
                int row = 0;
                while ((row < 5) && (row >= col)) {
                        if (row != col) {
                                System.out.print('*');
                                col += 1;
                        } else {
                                System.out.println('*');
                                row += 1;
                                col = 0;
                        }
                }
        }
                       
}

2. public class hw0 {
        public static void DrawTriangle (int N) {
                int col = 0;
                int row = 0;
                while ((row < N) && (row >= col)) {
                        if (row != col) {
                                System.out.print('*');
                                col += 1;
                        } else {
                                System.out.println('*');
                                row += 1;
                                col = 0;
                        }
                }       
        }
        public static void main(String[] args) {
               
                DrawTriangle(20);
        }
}

3. import java.util.Arrays;

public class ArrayEx {
        public static int max(int[] m) {
                //m = new int[] {3, 12, 1, 0, 9, 15, 7};
                int i = m.length-1;
                int m_max = 0;
                while ((i > 0) && (i < m.length)) {
                        if (m_max < m[i]) {
                                m_max = m[i];
                        } else {
                                m_max = m_max;
                        }
                        i -= 1;
                }
                return m_max;
        }
        public static void main(String[] args) {

                int[] numbers = new int[]{3, 12, 21, 100, 19, 15, 7};
               
                System.out.println("the max element of array " + Arrays.toString(numbers) + " is " + max(numbers));
        }
回复

使用道具 举报

🔗
whosays 2015-5-26 06:50:58 | 只看该作者
全局:
总共五道题吧?
五阶StarTriangle

自定义N阶StarTriangle,测试取20阶
找array中的最大值
回复

使用道具 举报

🔗
 楼主| hurricane_e 2015-5-26 12:07:44 | 只看该作者
全局:
whosays 发表于 2015-5-26 06:54
很丢人地发现自己不会发图片……本来截图效果最好的。。。就发下代码吧,这门课应该不存在honor code的问题 ...

恩恩~截图和代码都可以的=。=
回复

使用道具 举报

🔗
 楼主| hurricane_e 2015-5-26 12:10:30 | 只看该作者
全局:
1a.

public class stars {
        public static void main(String[] args){
                int row = 0;
                int SIZE = 5;
                while (row < SIZE){
                        int col = 0;
                        while (col < row){
                        System.out.print("*");
                        col += 1;
                        }
                        row += 1;
                        System.out.println("*");
                }       
        }
}

1b.

public class TriangleDrawer {
        public static void drawTriangle(int N){
                int row = 0;
                int SIZE = N;
                while (row < SIZE){
                        int col = 0;
                        while (col < row){
                                System.out.print("*");
                                col += 1;
                        }
                        row += 1;
                        System.out.println("*");
                }
        }
       
        public static void main(String[] args){
                drawTriangle(20);       
        }
}

2.

public class Max {

        public static int max(int[] m){
                int maxValue = m[0];
                for(int i= 1; i < m.length; i++){
                        if(m[i] > maxValue){
                                maxValue = m[i];
                        }
                }
                return maxValue;
        }
       
        public static void main(String[] args){
                int[] numbers = new int[]{9, 2, 15, 2, 22, 10, 6};
                System.out.print(max(numbers));
        }
}
回复

使用道具 举报

🔗
baiery 2015-5-26 22:34:25 | 只看该作者
全局:
好奇怪,61B都没人跟吗
回复

使用道具 举报

🔗
清扬婉 2015-5-27 01:47:56 | 只看该作者
全局:
// Creative Exercise 1a: Drawing a Triangle
public class drawingTriangle {
   public static void main(String[] args) {
      int i = 0;
      while(i < 5){
        for ( int j = 0; j <= i; j++){
            System.out.print("*");
         }
         System.out.println();
        i ++;
      }         
   }
}


public class drawTriangle {
   // pass the parameter
   public static void main(String[] args) {
      drawTri(20);
   }   
      
   // draw the triangle
   public static void drawTri(int N) {
      int i = 0;
      while(i < N){
         for ( int j = 0; j <= i; j++){
            System.out.print("*");
          }
          System.out.println();
          i ++;
      }         
   }
}


import java.util.*;

public class max {

   public static void max(int[] m) {
      //int res = Arrays.sort(m)[0];
       Arrays.sort(m);
       int len = m.length;
       System.out.println(m[len-1]);
   }
   
   public static void main(String[] args) {
      int[] numbers = new int[]{9, 2, 15, 2, 22, 10, 6};
      //System.out.println (max(numbers));      
      max(numbers);
   }
}

回复

使用道具 举报

🔗
whosays 2015-5-27 02:45:14 | 只看该作者
全局:
baiery 发表于 2015-5-26 22:34
好奇怪,61B都没人跟吗

可能大家都偏爱shewchuck的版本
回复

使用道具 举报

🔗
Casualet 2015-5-27 21:09:35 | 只看该作者
全局:
1a:
public class cs1{
    public static void main(String args[]){
        int i=1;
        int j=1;
        for(;i<=5;i++){
            for(j=1;j<=i;j++){
                System.out.print("*");
            }
                System.out.println("");

        }

    }

}
1b:
class ClassNameHere {
  public static void drawTriangle(int N){
      int i=1;
      int j=1;
       while(i<=N){
          j=1;
          while(j<i){
             System.out.print("*");
             j++;
         }
             System.out.println("*");
          i++;
      }

}
  public static void main(String[] args) {

         ClassNameHere.drawTriangle(20);
    }
}

exercise2:

class ClassNameHere {
   public static int max(int[] m) {
       int max=0;
       for(int i=0;i<m.length;i++){
           if(max<m[i]) max=m[i];
        }

       return max;
   }
   public static void main(String[] args) {
      int[] numbers = new int[]{9, 2, 15, 2, 22, 10, 6};

            int max;
           max=ClassNameHere.max(numbers);
           System.out.println(max);
     }
}

关于其他的作业,看了半天教程都没明白github怎么提交=_=; 有人知道那个instructional account是我们能注册的么,我看好像是一定得要伯克利的邮箱才行=_=
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表