package control;
public class MakeArrary
{ public static int[] Test(int statr,int end)
{
int[] z = null;
if(statr<=end)
{
int y=end-statr;
for(int x=statr,i=0;x<=y;x++,i++)
{
z[0+i]=x;
}
}
else
{
z=null;
}
return z;
}
public static void main(String[] args)
{
int[] z=Test(1,100);
int y=z.length;
for(int x=0;x<=y-1;x++)
{
System.out.print(z[x]);
}
}
}
public class MakeArrary
{ public static int[] Test(int statr,int end)
{
int[] z = null;
if(statr<=end)
{
int y=end-statr;
for(int x=statr,i=0;x<=y;x++,i++)
{
z[0+i]=x;
}
}
else
{
z=null;
}
return z;
}
public static void main(String[] args)
{
int[] z=Test(1,100);
int y=z.length;
for(int x=0;x<=y-1;x++)
{
System.out.print(z[x]);
}
}
}
解决方案 »
- String s1=new String("hello");String s2=new String("hello");创建对象问题
- 请问高手关于java3d的问题
- 如何配置程序?
- 如何不考虑年月日比较时刻,另外calendar的set不起作用
- pdfbox提取pdf文本,如果pdf中的字体本地没有,出现乱码
- 求救,关于正则表达式,急!!!!
- 将新闻内容保存到jsp文件访问中文乱码问题!UTF-8怎么转换为GBK
- Java美国学堂系列,欢迎专家进来指导!!
- swing中文显示为方框的问题
- 明日工作室(南京)电子技术有限公司
- 正整数n的立方可以表示为n个连续奇数的和,如何实现
- 我是超级菜新人,想问问this。
int[] z = null;
if (statr <= end) {
int y = end - statr;
z = new int[y];
for (int x = statr, i = 0; x <= y; x++, i++) {
z[0 + i] = x;
}
} else {
z = null;
}
return z;
} public static void main(String[] args) {
int[] z = test(1, 100);
int y = z.length;
for (int x = 0; x <= y - 1; x++) {
System.out.print(z[x]);
}
}你的int数组没有初始化长度,而是null,所以会报空指针错误,增加红色的代码
public static int[] Test(int statr,int end)
{
if(statr<=end)
{
int y=end-statr;
int[] z = new int[y]; //你之前没有只是定义了一个变量,使用的时候必须声明
for(int x=statr,i=0;x<=y;x++,i++)
{
z[i]=x; //这里没有必要i+0;
}
return z;
}
else
{
throw new IllegalArgumentException(" [statr] can not greater than [end] ! ");
//如果参数异常 抛出异常!
}
}