
Scanner sc = new Scanner (System.in)
List list = new ArrayList()//这里没起作用,舍弃掉
for(int i=0i<冲大students.lengthi++){//这里修改下
students[i]=(i+1)+""//还有举慧这里正判答
}
}
OK可以了,你测试下
null原因就是你建了一个空数组,名字你存到集合里去了
你随机取的时候取的是数组,数组里面是空的呀,当然是null了
1.abstract class Name {
private String name
// 抽象类中的抽象方法,不应该有方法体
public abstract boolean isStupidName(String name) {}
}
2.
public class Something {
void doSomething ()
{
private String s = "" // 方法中的修饰符不能是private,这个只能在类中使用
高肆 int l = s.length()
}
}
3.
abstract class Something {
private abstract String doSomething ()// 抽象方法不芦耐应该是private的,因为注定要被继承, 如果是private,就继承不了啦
}
4.
public class Something {
public int addOne(final int x) {
return ++x // final 修饰的x,不能被修改
}
}
5. 没错
public class Something {
戚哗轿 public static void main(String[] args) {
Other o = new Other()
new Something().addOne(o)
}
public void addOne(final Other o)
{
o.i++
}
}
class Other {
public int i
}
6. 没错
class Something {
int i
public void doSomething() {
System.out.println("i = " + i)
}
}
7.
class Something {
final int i // final修饰的变量要被初始化
public void doSomething() {
System.out.println("i = " + i)
}
}
8.
public class Something {
public static void main(String[] args) {
Something s = new Something()
// 静态方法main中调用doSomething, 但是doSomething不是static修饰的
System.out.println("s.doSomething() returns " + doSomething())
}
public String doSomething() {
return "Do something ..."
}
}
9. 写法没错,但是和文件名称不统一
class Something {
private static void main(String[] something_to_do)
{
System.out.println("Do something ...")
}
}
你试一下这个行不行,输入的时候是数字,数字,数字数字,数字。。。。。的格式,你把我注释的那个输入行(String stInput = input.next()
)的注释去掉,把我字符串写死的那行(String stInput = "1,2,34,57,8,9"
)删掉,就可以输入了
public static void main(String[] args){
Scanner input = new Scanner(System.in)
System.out.println("格式如下:1,2,34,57,8,9。输入数字:")
// String stInput = input.next()
/** 暂时写死了,方便测试,你将下面这句注释,上面那句打开即可 */
String stInput = "1,2,34,57,8,9"
// 输入按(英文分号)分割成字符串数组
String[] stArray = stInput.split("")
// 按字符串长度声明二维数组
double[][] arResults = new double[stArray.length][]
for (int i = 0 i < stArray.length i++)
{
// 字符串数组用分割成和目标结致字符串
String[] stForChange = stArray[i].split(",")
// 第二维开辟空间
arResults[i] = new double[stForChange.length]
扮游帆 for (int j = 0 j < stForChange.length j++)
{
arResults[i][j] = Double.parseDouble(stForChange[j])
}
}
/**循环输出*/
磨蔽 for (double[] i : arResults)
{
for (double j : i)
厅雹 {
System.out.print(j+" ")
}
System.out.println()
}
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)