Reading a single char in Java

后端 未结 8 813
暗喜
暗喜 2020-12-01 18:17

How can a char be entered in Java from keyboard?

8条回答
  •  盖世英雄少女心
    2020-12-01 18:27

    i found this way worked nice:

        {
        char [] a;
        String temp;
        Scanner keyboard = new Scanner(System.in);
        System.out.println("please give the first integer :");
        temp=keyboard.next();
        a=temp.toCharArray();
        }
    

    you can also get individual one with String.charAt()

提交回复
热议问题