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

[CS61B_Spring 2015] HW0 加分讨论帖

🔗
Lilzy 2016-1-30 09:41:44 | 只看该作者
全局:
public static void drawTriangle(int N){
    String s = "*";
    for (int i=0;i<N;i++){
        System.out.println(s);
        s +="*";
    }
}
public static int max(int[] m) {
    int i = m.length-1;
    int max = 0;
    while(i>=0){
        if(m>max){max=m[i];}
        i--;
    }
    return max;

}
public static void main(String args[]){
    [i]drawTriangle
(20);
    int[] numbers = new int[]{9, 2, 15, 2, 22, 10, 6};
    int res = max(numbers);
    System.out.println(res);
}
[/i][/i]

[i]----------[/i]
不知道自己做这事儿有没有意义...但先这么做下去吧!!!
回复

使用道具 举报

🔗
sophia2018 2018-5-23 10:01:10 | 只看该作者
全局:
/** HW0 Triangle*/
public class Triangle {
    public static void main (String[] args){
        int size =5;
        for(int i=0; i<size; i++){
            for(int j=0; j<=i; j++){
                System.out.print("*");
            }
            System.out.println(" ");
        }
回复

使用道具 举报

🔗
sophia2018 2018-5-23 13:50:05 | 只看该作者
全局:
hw0 1b
        public class YourClassNameHere {
2          public static void drawTriangle(int n){
3            int size = n;
4            int row = 0;
5            while(row < n){
6              int col = 0;
7              while(col<=row){
8                System.out.print("5");
9                col+=1;
10                }
11                System.out.println(" ");
12                row+=1;
13              }
14            }
15            public static void main(String[] args) {
16            drawTriangle(10);
17       
18            }
19        }
回复

使用道具 举报

🔗
sophia2018 2018-5-23 14:25:29 | 只看该作者
全局:
HW0 exercise2
public class ClassNameHere {
2           public static int max(int[] m) {
3             int max =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           }
16        }
回复

使用道具 举报

🔗
sophia2018 2018-5-24 01:49:26 | 只看该作者
全局:
HW0 exercise4:
These Python Tutor users are asking for help right now. Please volunteer to help!
user_8db from Chicago, Illinois, US needs help with Python3 - 2 people chatting - click to help (active a few seconds ago, requested 25 minutes ago)
user_2d5 from Delft, Netherlands needs help with Python3 - click to help (IDLE: last active 28 minutes ago, requested 41 minutes ago)
user_b66 from Waltham, Massachusetts, US needs help with Python3 - click to help (IDLE: last active 11 minutes ago, requested 29 minutes ago)
Java
1        public class BreakContinue {
2          public static void windowPosSum(int[] a, int n) {
3            for(int i=0;i<a.length;i++){
4              if(a[i]<=0){
5                continue;}
6                for(int j=i;(j+1)<=(i+n);j++){
7                  a[i]+=a[j+1];
8                  if((j+1) >= (a.length-1)){
9                    break;}
10                  }
11             
12              }
13            /** your code here */
14          }
15       
16          public static void main(String[] args) {
17            int[] a = {1, 2, -3, 4, 5, 4};
18            int n = 4;
19            windowPosSum(a, n);
20       
21            // Should print 4, 8, -3, 13, 9, 4
22            System.out.println(java.util.Arrays.toString(a));
23          }
24        }
回复

使用道具 举报

🔗
cmat2 2020-5-2 01:00:38 | 只看该作者
全局:
/** Draw a Triangular*/
2       
3        public class DrawTri{
4            
5          public static void main(String[] args){
6            int row = 1;
7            int col = 1;
8            int size = 5;
9            while (row <= size){
10              int i = 0;
11              while (i < col){
12                System.out.print("*");
13                i = i +1;
14                }
15                row = row + 1;
16                col = col + 1;
17                System.out.println("");
18              }
19            
20            }
21          }
回复

使用道具 举报

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

本版积分规则

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