public static char charAt(String str,int index) throws Exception{ char[] value = str.toCharArray(); if(index>=0&&index<str.length()){ return value[index]; } else throw new Exception("Argument Error"); }
我也没有太看清楚lz是什么意思~ lz不妨说的明白点 ~
public class CsdnTest { private final int value[]; private final int offset; private final int count; public CsdnTest(int[] value) { this.offset = 0; this.count = value.length; this.value = value; } public int intAt(int index) { if ((index < 0) || (index >= count)) { throw new RuntimeException("超出数组范围!"); } return value[index + offset]; }
public static void main(String[] args) { int[] value = {0,1,2,3,4,5}; CsdnTest test = new CsdnTest(value); System.out.println(test.intAt(1)); System.out.println(test.intAt(5)); System.out.println(test.intAt(6)); }}
public static char charAt(String str,int index) throws Exception{
char[] value = str.toCharArray();
if(index>=0&&index<str.length()){
return value[index];
}
else
throw new Exception("Argument Error");
}
lz不妨说的明白点 ~
public class CsdnTest { private final int value[]; private final int offset; private final int count;
public CsdnTest(int[] value) {
this.offset = 0;
this.count = value.length;
this.value = value;
}
public int intAt(int index) {
if ((index < 0) || (index >= count)) {
throw new RuntimeException("超出数组范围!");
}
return value[index + offset];
}
public static void main(String[] args) {
int[] value = {0,1,2,3,4,5};
CsdnTest test = new CsdnTest(value);
System.out.println(test.intAt(1));
System.out.println(test.intAt(5));
System.out.println(test.intAt(6));
}}
char charAt(int index)
返回指定索引处的 char 值。
方法。3楼以出答案。