Skip to content
Advertisement

Tag: char

Converting a scanner.next() to a char[]

I want to give a function a char array from scanner.next(). I only get an error message if I try to convert it like I do it now: This is the errormessage I get: It also shows this error on the other ones where I want to pass the char[] over. Need to add more text cause they say it

why can’t I add chars to a new string?

code: The second line is wrong for some reason and I don’t know why Answer The book is wrong, and Eclipse is right. In Java, you can write “abc” + whatever, or whatever + “abc”, and it concatenates the strings — because one side is a String. But in st.charAt(0)+st.charAt(st.length()-1)), neither side is a String. They’re both chars. So Java

start a char array from a certain index

I have a char array called data. I should write a method that makes it possible to return the array but with a starting point that is an integer variable called beginIndex. Example: array contains ‘A’, ‘B’, ‘C’, ‘D’ and beginIndex = 2. Then it should return ‘B’, ‘C’, ‘D’ (yes the index himself in this case the 2nd letter

Char variable minus char variable parse to Int in java

I know this is trivial, but I can’t find the proper explication. I have the following code How does this parsing work? Answer As long as the character is a digit, you can get the equivalent int value by subtracting ‘0’. The ASCII coding for ‘0’ is decimal 48, ‘1’ is decimal 49, etc. So ‘8’ – ‘0’ = 56

How do I change the distance between words?

How can I change the distance between words in a string in Android Studio using the methods? I need the distance to be about half the size of the standard space. as I understand it, after BackgroundColorSpan(Color.BLACK), you can add a parameter to change the distance between words. Answer There are different kinds of spaces with different widths: →󠀠← –

How to replace even values in string with ASCII value?

Suppose I have a string as ABCDEFG. I want to replace the even values of this string with their ASCII value. How should I do? Answer You are almost there, you simply need to build the resulting string. Strings are immutable, so replacing would create a new String each time. I would suggest a StringBuilder for this task, but you

Advertisement