作业3-5;不懂错在哪。。看不懂

作业3-5;不懂错在哪。。看不懂

public class CharDemo {

    public static void main(String[] args) {

Scanner.sc=new Scanner(System.in);

System.out.println("请输入一个字母");

String cha=next();

cha=cha.toLowercase();

//定义一个字符变量并初始化

switch (cha)

{

   case "a":

       System.out.println("元音字母:"+cha);break;

   case "e":

       System.out.println("元音字母:"+cha);break;

   case "i":

       System.out.println("元音字母:"+cha);break;

   case "o":

       System.out.println("元音字母:"+cha);break;

   case "u":

       System.out.println("元音字母:"+cha);break;

   default:

   System.out.println("不是元音字母");

 

}

//使用switch结构判断是否为元音字母,并输出对应的信息

}

}




CharDemo.java:3: error: cannot find symbol
Scanner.sc=new Scanner(System.in);
^
 symbol:   variable Scanner
 location: class CharDemo
CharDemo.java:3: error: cannot find symbol
Scanner.sc=new Scanner(System.in);
              ^
 symbol:   class Scanner
 location: class CharDemo
CharDemo.java:5: error: cannot find symbol
String cha=next();
          ^
 symbol:   method next()
 location: class CharDemo
CharDemo.java:6: error: cannot find symbol
cha=cha.toLowercase();
      ^
 symbol:   method toLowercase()
 location: variable cha of type String
4 errors

正在回答

登陆购买课程后可参与讨论,去登陆

2回答

CharDemo.java:3: error: cannot find symbol
Scanner.sc=new Scanner(System.in);
^
//package语句后加入:
import java.until.Scanner;

symbol: variable Scanner
location: class CharDemo
CharDemo.java:3: error: cannot find symbol
Scanner.sc=new Scanner(System.in);
^
//没有 · ,用空格
Scanner sc = new Scanner(System.in);

symbol: class Scanner
location: class CharDemo
CharDemo.java:5: error: cannot find symbol
String cha=next();
^
//String cha = sc.next();

symbol: method next()
location: class CharDemo
CharDemo.java:6: error: cannot find symbol
cha=cha.toLowercase();
^
//cha = cha.toLowerCase();
symbol: method toLowercase()
location: variable cha of type String
4 errors

最爱西江月 2018-01-12 08:29:57

Scanner没有直接读入单个字符的方法!

问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师