Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
The charAt isn't working... It's returning the hash code and not the value of a part in a structure.
Ex.: charAt(0) where is '1' is returning 49 and not 1
What Am I able to do?!
It >>is<< working. It is returning that character as a char which (presumably) you are assigning to an int and printing. The numeric value of the ASCII / Unicode codepoint for the character '1' is 49. If you want to print / display this as a character, cast the int to a char. (Or don't assign it to an int in the first place.)
For the record, the hashCode value returned by Character is identical to the character value. Strictly speaking a char doesn't have a hashCode because it is a primitive value, and primitives don't have methods.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
i would like to know first why Boolean is set to be false at the beginning and the pre-last "else" i ca not understand that condition that code is suppose to differentiate vowels from consonants ??
https://beginnersbook.com/2017/09/java-program-to-check-vowel-and-consonant-using-switch-case/
Please post the Code when you ask a Question and don't just put a link in here.
To answer your Question the Code is correct, just the 2nd ; in
boolean isVowel=false;;
isn't necessary. The boolean is set to false to Show that they assume by Default that the given char is no Vowel.
The switch basically checks if the given char is an a,e,i… and has to check for upper and lower case because they are treated different. If the given char Matches any of the given values the boolean is set to true because the char is a vowel.
The second last else Statement checks the UTF-16 values of the Alphabet, you can cast a char to an int which determines ist value in UTF-16 encoding for the lower cases it is 97-122 and for the upper cases their values are 65-90. If the int value of the char is not in this range the char is not in the Alphabet. You can refer to an ascii table to know which char is equivalent to which int.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have labels which is a list of String and is equal to [0,1]. However the following line returns -1 while I expect it to return 1. Any idea what could be wrong or missing?
definition:
maxLabel is an integer initially set to -1.
public List labels;
where the unexpected result happens, while maxLabel is equal to 1:
int maxLabelIndex=labels.indexOf(maxLabel);
indexOf returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element. More formally, returns the lowest index i such that (o==null ? get(i)==null
In your case the index of element "1" is 1, thats why you will get 1. BUT if you will pass int maxLabel = 1; notice that maxLabel is declared as type int then you will get -1 because Collection of strings doesn't contains an object of type Integer.
Basically indexOf method take as parameter o of type Object. Whenever you pass a different Object type (e.g. you declared your List of type String and you are checking for different types like Integer,Double,int,long, etc.), you can expect to get -1
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
What type should I be getting for a char(36) UUID value in a MySQL query?
Query:
ResultSet res = st.executeQuery("SELECT uuid FROM playerdata");
String variable:
String uuid = res.getString("uuid");
The above line is the part I am unsure about. Is a CHAR value a String, an Object, or something else?
Example value:
456f5080-f3b5-11e3-ac10-0800200c9a66
I've tried both strings and objects, but neither seem to work. Just a quick clarification would be greatly appreciated!
Char(36) refers to the datatype of the field in your database. You can store strings up to 36 characters. If you store less than 36 characters, your database will store trailing zeros. In your case, it appears that you are storing UUIDs there, which are 36 character strings.
Since you tagged this as java, you can read this to see what char means in java.
In other contexts, char(36) is a function that will return a dollar sign. The argument of that function has to be an integer and is treated as an ascii code. Sql Server is one such context.
Should be a normal string only.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
What significance does a letter after a number have? For example the bellow table for primitive types in Java has letters after the default values of long float and double.
I tested and as far as I can tell they never make a difference. I've also seen things like this in C and C++, for example how the NULL macro sometimes expands to 0L.
It does make a difference. It just depends on what your values are.
First and foremost, Java will treat all integral declarations as an int unless you specify the L (or l) suffix.
This means that, while this declaration is invalid:
System.out.println(5_000_000_000_000); // too large for an int
...this declaration would be:
System.out.println(5_000_000_000_000L);
Java will also treat all floating-point declarations as a double unless you specify f or F. You could also specify d or D, but this is an optional and implied declaration that your literal type is a double.
Another example: while this declaration is valid for a double:
System.out.println(1.17e200);
...this one isn't:
float f = 1.17e200f; // too large
The behavior for other languages (C, C++) would be specific to which standard you're using, but it's not quite what you're thinking - a macro is simply a pre-compiler text replace, so wherever the compiler sees NULL, it would replace it with 0.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Why am i getting a "Invalid hex literal number" for this
int number = 0xgetInt();
and not for this
int number = 0x555;
getInt() is a function call, not a "literal number" as the exception says. There's no reason to try to convert that int to hex at this particular spot, since it's stored as a variable anyway.
0x is the start of literal and is converted into the appropriate value at compile time where as getInt() is evaluated at runtime.
You probably want
int number = Integer.parseInt( getNext(), 16)
A "hex" or hexadecimal number can only contain the digits 0-9 and characters a-f (or A-F). In java, prefixing a number with "0x" indicates to the compiler that it's a hexadecimal integer literal. 0xgetInt() is therefore interpreted as an integral value, but it contains invalid hexadecimal digits. 0x555, on the other hand, is a valid hex value that corresponds to 1365 decimal. If 0xgetInt() is supposed to be a method name, you'll have to change it to get rid of the "0x" prefix to avoid this problem.
Because you can't start a Java identifier with a number, and because a number can start with 0x but it can't continue with getInt. It's not valid Java, at the lexical level.
It's unclear what you're trying to do here. If you're trying to convert the result of getInt() to hex, you're barking up the wrong tree, it's binary, you would need to convert it to a String with Integer.toString(getInt(), 16).