java中使用switch语句怎么实现下图
展开全部
public static void main(string args[])
{
//编写内容
for(int i=0;i<5;i++)
{
switch(i)
{
case 0:
system.out.println("student"+i+"'s result is A");
break;
case 1:
system.out.println("student"+i+"'s result is B");
break;
case 2:
system.out.println("student"+i+"'s result is C");
break;
case 3:
system.out.println("student"+i+"'s result is D");
break;
case 4:
system.out.println("student"+i+"'s result is F");
break;
default:
break;
}
}
}
{
//编写内容
for(int i=0;i<5;i++)
{
switch(i)
{
case 0:
system.out.println("student"+i+"'s result is A");
break;
case 1:
system.out.println("student"+i+"'s result is B");
break;
case 2:
system.out.println("student"+i+"'s result is C");
break;
case 3:
system.out.println("student"+i+"'s result is D");
break;
case 4:
system.out.println("student"+i+"'s result is F");
break;
default:
break;
}
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
for(int i=0;i<=5;i++){
switch(i){
case :0 System.out.println("student0's result is A!");break;
case :1 System.out.println("student1's result is B!");break;
case :2 System.out.println("student2's result is C!");break;
case :3 System.out.println("student3's result is D!");break;
case :4 System.out.println("student4's result is F!");break;
}
}
switch(i){
case :0 System.out.println("student0's result is A!");break;
case :1 System.out.println("student1's result is B!");break;
case :2 System.out.println("student2's result is C!");break;
case :3 System.out.println("student3's result is D!");break;
case :4 System.out.println("student4's result is F!");break;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public void testForSwitch(){
for(int i=0;i<=4;i++){
char c = 'A';
switch(i){
case 0:
break;
case 1:
c = 'B';
break;
case 2:
c = 'C';
break;
case 3:
c = 'D';
break;
case 4:
c = 'P';
break;
}
System.out.println("Student"+i+"'s result is "+c+"!");
}
}
for(int i=0;i<=4;i++){
char c = 'A';
switch(i){
case 0:
break;
case 1:
c = 'B';
break;
case 2:
c = 'C';
break;
case 3:
c = 'D';
break;
case 4:
c = 'P';
break;
}
System.out.println("Student"+i+"'s result is "+c+"!");
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询