Lintcode455-StudentID-Easy
Implement a class Class with the following attributes and methods:
- A public attribute
studentswhich is a array ofStudentinstances. - A constructor with a parameter n, which is the total number of students in this class. The constructor should create n Student instances and initialized with student id from 0 ~ n-1
Example
Example 1:
Input: 3
Output: [0, 1, 2]
Explanation: For 3 students, your cls.students[0] should equal to 0, cls.students[1] should equal to 1 and the cls.students[2] should equal to 2.
Example 2:
Input: 5
Output: [0, 1, 2, 3, 4]
注意:
- 数组的声明和创建:数组声明不能制定大小(因为只是创建了一个引用变量),数组创建时必须制定大小!
- Java 对象和对象的引用
- Class类:先声明一个数组类型的引用变量,在构造方法中才能使引用变量指向创建的数组,因为有了参数n,知道数组长度后,才能创建数组。
代码:
class Student {
public int id;
public Student(int id) {
this.id = id;
}
}
public class Class {
public Student[] students; // 声明Student类型数组,即创建一个引用
public Class(int n) {
this.students = new Student[n]; // 创建Student类型数组,将引用(students)指向此数组
for (int i = 0; i < n; i++) {
students[i] = new Student(i);
}
}
}
Lintcode455-StudentID-Easy的更多相关文章
- 【转】Windows下使用libsvm中的grid.py和easy.py进行参数调优
libsvm中有进行参数调优的工具grid.py和easy.py可以使用,这些工具可以帮助我们选择更好的参数,减少自己参数选优带来的烦扰. 所需工具:libsvm.gnuplot 本机环境:Windo ...
- Struts2 easy UI插件
一.easy UI是类似于jQuery UI的插件库,它提供了丰富的各种常用插件:tree.datagrid... tree插件: 语法:$(selector).tree([settings]); 常 ...
- Easy UI常用插件使用
一.easy UI是类似于jQuery UI的插件库,它提供了丰富的各种常用插件:tree.datagrid... tree插件: 语法:$(selector).tree([settings]); 常 ...
- UVA-11991 Easy Problem from Rujia Liu?
Problem E Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for ...
- CodeForces462 A. Appleman and Easy Task
A. Appleman and Easy Task time limit per test 1 second memory limit per test 256 megabytes input sta ...
- easy ui插件
简介: easy UI是类似于jQuery UI的插件库 注意:多脚本同时使用时,注意脚本冲突问题. 常用插件: 1.tree插件(tree插件实现动态树形菜单) 2.datagrid插件(datag ...
- 用TPP开启TDD的easy模式
Test-Drived Development 测试驱动开发三步曲:写一个失败的测试用例->编写生产代码通过这个测试用例(transformation)->重构(refactor).重构是 ...
- Easy Sysprep更新日志-skyfree大神
Easy Sysprep更新日志: Skyfree 发表于 2016-1-22 13:55:55 https://www.itsk.com/forum.php?mod=viewthread&t ...
- [官方软件] Easy Sysprep v4.3.29.602 【系统封装部署利器】(2016.01.22)--skyfree大神
[官方软件] Easy Sysprep v4.3.29.602 [系统封装部署利器](2016.01.22) Skyfree 发表于 2016-1-22 13:55:55 https://www.it ...
- [原创] Easy SysLite V1.2 (2016.5.29更新,新增加WIN10支持,一个程序适配所有系统减肥)
[原创] Easy SysLite V1.2 (2016.5.29更新,新增加WIN10支持,一个程序适配所有系统减肥) nohacks 发表于 2016-5-29 17:12:51 https:// ...
随机推荐
- SpringMVC常用注解的规则(用法)
SpringMVC注解 @RequestMapping用法: a. 用在controller方法上: 标记url到请求方法的映射, 其实就是通过一段url地址, 找到对应需要执行的 ...
- Python数据类型深入学习之数字
一. 数字常量 1. 下面来看看Python的数字常量中都要哪些类型: 数字 常量 129,-89,0 一般整数 9999848499999L,4594646469l 长整型数(无限大小) 1.232 ...
- mysql查询语句 查询方式
- Codeforce 294A - Shaass and Oskols (模拟)
Shaass has decided to hunt some birds. There are n horizontal electricity wires aligned parallel to ...
- bzoj4444 国旗计划
题目链接 倍增,预处理出每个点往后$2^i$个应该选哪个人 我用的treap就是快 #include<algorithm> #include<iostream> #includ ...
- Spring Boot 实现RESTful webservice服务端示例
1.Spring Boot configurations application.yml spring: profiles: active: dev mvc: favicon: enabled: fa ...
- Eloquent JavaScript #04# Objects and Arrays
要点索引: JSON More ... 练习 1.补:js字符串的表达方式有三种: "" 和 '' 没什么区别,唯一区别在于 "" 中写 "要转义字符 ...
- 《2015 html5 iweb 峰会观会后感》
今天是2015 html5 iweb 峰会,大会在早上8:30,就开始了,没想到被坑了,看错一个字,把"国际会议中心",看成了"国家会议中心".大约过了10多 ...
- Bugku-CTF之web基础$_POST
Day4 web基础$_POST http://123.206.87.240:8002/post/ 本题要点: POST传参 打开发现这样一段代码
- vue.js not detected 解决办法-vue.js devtools 安装
国外网站:https://www.crx4chrome.com/ 国内网站:http://www.cnplugins.com/ http://chromecj.com/web-development/ ...