logo

Skaitytuvas ir nextChar () Java

„Java“ skaitytuvo klasė palaiko nextInt(), nextLong(), nextDouble() ir tt Bet nėra nextChar() (žr. tai pavyzdžiams) Norėdami perskaityti ženklą, naudojame next().charAt(0) . Funkcija next() grąžina kitą žetoną/žodį įvestyje kaip eilutę, o funkcija charAt(0) grąžina pirmąjį tos eilutės simbolį, skaičių 0 funkcijoje CharAt( NUMERIS ) reiškia įvestos eilutės vieno žodžio indeksą ir nustato šį indekso simbolį į kintamąjį char.

Java




įterpimo rūšiavimas java





// 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);> >}> > }> > > >

java nulinis patikrinimas



>

>

mašinraštis kiekvienam

Įvestis:

ge>

Išvestis:

c = e>