Сбой сценария MongoDB в кластере

Scanner key = new Scanner(System.in);
//shortcut way 
char firstChar=key.next().charAt(0);  
//how it works;
/*key.next() takes a String as input then,
charAt method is applied on that input (String)
with a parameter of type int (position) that you give to get      
that char at that position.
You can simply read it out as: 
the char at position/index 0 from the input String
(through the Scanner object key) is stored in var. firstChar (type char) */

//you can also do it in a bit elabortive manner to understand how it exactly works
String input=key.next();  // you can also write key.nextLine to take a String with spaces also
char firstChar=input.charAt(0);
char charAtAnyPos= input.charAt(pos);  // in pos you enter that index from where you want to get the char from

Кстати, вы не можете взять char непосредственно в качестве входа. Как вы можете видеть выше, сначала берется строка, затем charAt (0); найден и сохранен

0
задан chamathabeysinghe 3 March 2019 в 12:32
поделиться