Javaのスキャナクラス nextInt()、nextLong()、nextDouble() などをサポートします。ただし、nextChar() はありません (「 これ 例) 文字を読み取るには、次を使用します。 next().charAt(0) 。 next() 関数は入力内の次のトークン/単語を文字列として返し、charAt(0) 関数はその文字列の最初の文字、つまり CharAt( の関数内の数値 0) を返します。 番号 ) は、入力された文字列の 1 つの単語のインデックスを表し、そのインデックス文字を char 変数に設定します。
ジャワ
Javaで文字列をintに変換する
// Java program to read character using Scanner> // class> import> java.util.Scanner;> public> class> ScannerDemo1 {> >public> static> void> main(String [] args){> >Scanner sc =>new> Scanner(System.in);> >char> c = sc.next().charAt(>1>);> >// here this is the indexing of the element to take //> >System.out.println(>'c = '>+c);> >}> > }> > > > |
>
>
入力:
ge>
出力:
c = e>