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

[CS61B_Spring 2015] HW0 加分讨论帖

🔗
 楼主| hurricane_e 2015-5-28 04:18:41 | 只看该作者
全局:
Casualet 发表于 2015-5-27 21:09
1a:
public class cs1{
    public static void main(String args[]){

github提交的那个貌似是上那个课的学生才可以,我们应该不行=。=
所以写出来就好,不用提交github~
回复

使用道具 举报

🔗
xuxiaoyang626 2015-5-31 20:48:32 | 只看该作者
全局:





第一次跟~补交作业~~
回复

使用道具 举报

🔗
karte_polo 2015-6-2 15:08:44 | 只看该作者
全局:
1a

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

1b:
public class triangle {
    public static void drawtriangle(int D) {
int col = 0;
int row = 0;
while (row < D) {
while (col <= row) {
   System.out.print('*');
   col = col+1;
}
   System.out.println();
   row = row + 1;
   col = 0;
}
    }
public static void main(String[] args){
   triangle.drawtriangle(10);
   
}
}

exercise2:

public class MaxNum {
   public static int max(int[] m) {
      int v = 0;
      int l = m.length;
      for (int n=0;n<l;n++){
         if (m[n]>v){
          v = m[n];
         }
      }
       return v;
   }
   public static void main(String[] args) {
      int[] numbers = new int[]{9, 2, 15, 2, 22, 10, 6};
      System.out.print("Max Num is "+MaxNum.max(numbers));
   }
}

回复

使用道具 举报

🔗
geminiiiiiii 2015-6-17 00:49:52 | 只看该作者
全局:
public class triangle() {
    public static void main() {
        int SIZE = 5;
        int row = 0;
        while(row <= size){
            int col = 0;
            while(col < row){
                System.out.print('*');
                col = col + 1;
            }
            System.out.println();
            row = row + 1;
        }
    }
}

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

public class ClassNameHere {
   public static int max(int[] m) {
        m = numbers[0];
        i = 0;
        while(numbers[i]>m){
            m=numbers[i];
            i++;
        }
        return 0;
   }
   public static void main(String[] args) {
      int[] numbers = new int[]{9, 2, 15, 2, 22, 10, 6};
      System.out.prinIn(max(numbers))      
   }
}
回复

使用道具 举报

🔗
西风吹草 2015-6-17 10:47:10 | 只看该作者
全局:
1a.
public class Drawing {
        public static void main(String[] args){
                int i = 1;
                while (i <= 5){
                        int j = 1;
                        while (j < i){
                                System.out.print("*");
                                j += 1;
                        }
                        System.out.println("*");
                        i += 1;
                }
        }
}

1b.
public class Drawtriangle {
        public static void drawTriangle(int N){
                int i = 1;
                while (i <= N){
                        int j = 1;
                        while (j < i){
                                System.out.print("*");
                                j += 1;
                        }
                        System.out.println("*");
                        i += 1;
                }
        }
       
        public static void main(String[] args){
                drawTriangle(20);
        }
}

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

使用道具 举报

🔗
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. }
复制代码

评分

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

查看全部评分

回复

使用道具 举报

🔗
忆梦前尘 2015-7-10 12:09:20 | 只看该作者
全局:
暑假的空闲就是要多加训练!  //是不是homework0的作业只能上传在这里啊?我只发现这个帖子了。

第一次不知道附件的效果发出来是什么样子的,贴个代码吧。
Drawing a Triangle

public class Triangle {

        (public) static void printstar(int i){ //compiled successfully before I saw public static should be used for this HW
                for (int j = 0; j < i; j++) {
                        System.out.print("*");
                }
        }
        public static void main(String[] args) {
                for (int i = 1; i < 6; i++) {
                        printstar(i);
                        System.out.println(" ");
                }
        }
}

DrawTraingle
public class Triangle {

        public static void printstar(int i){
                for (int j = 0; j < i; j++) {
                        System.out.print("*");
                }
        }
        public static void DrawTriangle(int k) {
                for (int i = 0; i < k; i++) {
                        printstar(i);
                        System.out.println(" ");
                }
        }
        public static void main(String[] args) {
                        int N = 20;
                        DrawTriangle(N);
        }

}

Exercise 2 maxvalue of an array
public class Array{
                   public static int max(int[] m) {
                           int maxValue = 0;
                           for (int i = 0; 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};
                      int maxVal = max(numbers);
                      System.out.println(maxVal);
                   }

}
其实应该改掉return 0;的。。太二了。。
第一次交作业,应该没什么问题了。





补充内容 (2015-7-18 21:58):
好像多贴了一张图。。求一个点评……等学分等了10天了。。

Screen Shot 2015-07-09 at 20.19.48.png (117.67 KB, 下载次数: 0)

Triangle

Triangle
回复

使用道具 举报

🔗
忆梦前尘 2015-7-10 12:10:53 | 只看该作者
全局:
本帖最后由 忆梦前尘 于 2015-7-9 20:18 编辑
忆梦前尘 发表于 2015-7-9 20:09
暑假的空闲就是要多加训练!  //是不是homework0的作业只能上传在这里啊?我只发现这个帖子了。

第一次 ...

原来上传图片是这个效果。。。求问怎么在eclipse上把一段代码向左移?我只会向右移。。
怎么变成回复了。。。代码有什么缺点还请各位同行多多指点~

鞠躬致谢~
回复

使用道具 举报

🔗
HNAKXR 2016-1-26 21:34:01 | 只看该作者
全局:

回复

使用道具 举报

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

本版积分规则

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