循环输出数组中元素的值:
sports
game
movie
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3
at HelloWorld.main(HelloWorld.java:10)
为什么提示下标越界
sports
game
movie
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3
at HelloWorld.main(HelloWorld.java:10)
为什么提示下标越界
2015-06-04
int i;
// 定义一个长度为 3 的字符串数组,并赋值初始值
String[] hobbys = { "sports", "game", "movie" };
System.out.println("循环输出数组中元素的值:");
// 使用循环遍历数组中的元素
for(i=0;i<hobbys.length;i++){
System.out.println(hobbys[i]);
}
// 定义一个长度为 3 的字符串数组,并赋值初始值
String[] hobbys = { "sports", "game", "movie" };
System.out.println("循环输出数组中元素的值:");
// 使用循环遍历数组中的元素
for(i=0;i<hobbys.length;i++){
System.out.println(hobbys[i]);
}
2015-06-04
{
switch (char){
case '一'||'三'||'五':
System.out.println("早餐吃包子");
break;
case '日':
System.out.println("主席套餐");
break;
}
求问: case里面多个值不能用 || 符号或表示么
switch (char){
case '一'||'三'||'五':
System.out.println("早餐吃包子");
break;
case '日':
System.out.println("主席套餐");
break;
}
求问: case里面多个值不能用 || 符号或表示么
2015-06-04
public class HelloWorld{
public static void main(String[] args) {
double avg1=78.5;
int rise=5;
double rice2=rice;
double avg2=avg1+rise2;
System.out.println("考试平均分:"+avg1);
System.out.println("调整后的平均分:"+avg2);
}
}
public static void main(String[] args) {
double avg1=78.5;
int rise=5;
double rice2=rice;
double avg2=avg1+rise2;
System.out.println("考试平均分:"+avg1);
System.out.println("调整后的平均分:"+avg2);
}
}
2015-06-04
System.out.println("a等于b:" + (a == b));
System.out.println("a大于b:" + (a > b));
System.out.println("a小于等于b:" + (a <= b));
System.out.println("str1等于str2:" + (str1 == str2));
System.out.println("a大于b:" + (a > b));
System.out.println("a小于等于b:" + (a <= b));
System.out.println("str1等于str2:" + (str1 == str2));
2015-06-03