Good day! This is my switch menu for a project in java! When I put a diferent letter (letter that it´s not in the switch) I get this error message, and when I try one of the correct letter I get the same error message again: This is my code: I tryed with numbers and I got the same error
Tag: char
What is the difference between chars() and codePoints() method in CharSequence interface?
I read javadoc, but don’t understand the differences, both of them return same result. Also can anyone explain what is ‘zero-extending’ means? Javadoc of chars() method Returns a stream of int zero-extending the char values from this sequence. Any char which maps to a surrogate code point is passed through uninterpreted. The stream binds to this sequence when the terminal
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
char array not modified after passing trough a method that should modify it in java
Hello i have a problem with the code i’ve written down below. From what i’ve understand so far what is passed to the method is the memory reference of charArray thus the variable charArray and tabCar should point at the same memory place. thus the modification done in my method reverseArray should be seen but somehow the 2 print statement
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: →← –
Leetcode: Add Binary (Java) How can it perform addition between one char and one int?
Apparently, this code works for the solution, I’m just having a hard time understanding the question. For this line: sum is an integer, a.charAt(len1) returns a char, how can it perform addition between an integer and a char? also, what does it mean to – ‘0’? Answer chars are essentially smaller ints with fancy printing associated to them. A char
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