java吧 关注:1,253,979贴子:12,743,190
  • 1回复贴,共1

为什么在String day处与case1出现错误packa

只看楼主收藏回复

为什么在String day处与case1出现错误
package idea;
import java.util.Scanner;
public class Hollo {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println();
int day = sc.nextInt();
String day = "";
{
switch (day) {
case 1:
day = "星期一";
break;
case 2:
day = "星期二";
break;
case 3:
day = "星期三";
break;
case 4:
day = "星期四";
break;
case 5:
day = "星期五";
break;
case 6:
day = "星期六";
break;
case 7:
day = "星期日";
break;
default:
System.out.println(day);
}
}
}
}


IP属地:广东来自Android客户端1楼2021-07-05 15:41回复
    你不能在同一个作用域中声明俩名字一样的变量啊,你int的也叫day,String的也叫day,编译器很难受的


    IP属地:浙江2楼2021-07-05 17:31
    回复