Character getnumericvalue java что это

от admin

Java — Character getNumericValue Method

The Java Character getNumericValue() method is used to get the integer value that a specified Unicode character represents. For example, the character ‘\u216C’ (the roman numeral fifty) will return an integer with a value of 50.

The letters A-Z in their uppercase (‘\u0041’ through ‘\u005A’), lowercase (‘\u0061’ through ‘\u007A’), and full width variant (‘\uFF21’ through ‘\uFF3A’ and ‘\uFF41’ through ‘\uFF5A’) forms have numeric values from 10 through 35. This is independent of the Unicode specification, which does not assign numeric values to these char values.

Note − Extreme Characters (Character.MAX_VALUE and Character.MIN_VALUE) hold no numeric values.

Syntax

Following is the syntax for Java Character getNumericValue() method

Parameters

ch − the character to be converted

codePoint − the Unicode code point to be converted

Return Value

This method returns the numeric value of the character, as a non-negative int value; -2 if the character has a numeric value that is not a non-negative integer; -1 if the character has no numeric value.

Example

The following example shows the usage of Java Character getNumericValue(char ch) method.

Output

Let us compile and run the above program, this will produce the following result −

Example

The following example shows the usage of Java Character getNumericValue(int codePoint) method.

Output

Let us compile and run the above program, this will produce the following result −

Example

In another example, we pass integers that are not in a code point format as arguments to this method.

Output

If we compile and run the program, the output is obtained as −

Example

Symbols are non-numeric values. Hence, when they are passed as arguments to the method, -1 is returned. Let us see the program below −

Output

The program above is to be compiled and run to obtain the output given as follows −

Character getnumericvalue java что это

lang.Character class wraps the value of a primitive data type – char to an object of datatype char and this object contains single field having the data type – char. This class provides no. of methods regarding character manipulations like convert them from lowercase to uppercase. Character class is based on Unicode Standards to provide character information.
Class Declaration:

Читать:
High definition audio device что это

Following methods of Character class are discussed here :

  1. charCount() :java.lang.charCount() method uses Unicode point to return the number of char values to represent the argument char values. A Unicode code point is used for character values in the range between U+0000 and U+10FFFF and for 16-bit char values that are code units of the UTF-16 encoding.
    Syntax :

Java code explaining use of charCount(), charValue(), codePointat() methods

Character getnumericvalue java что это

Javatpoint Services

JavaTpoint offers too many high quality services. Mail us on [email protected], to get more information about given services.

  • Website Designing
  • Website Development
  • Java Development
  • PHP Development
  • WordPress
  • Graphic Designing
  • Logo
  • Digital Marketing
  • On Page and Off Page SEO
  • PPC
  • Content Development
  • Corporate Training
  • Classroom and Online Training
  • Data Entry

Training For College Campus

JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected]vatpoint.com.
Duration: 1 week to 2 week

Like/Subscribe us for latest updates or newsletter RSS Feed Subscribe to Get Email Alerts Facebook Page Twitter Page YouTube Blog Page

Java Character getNumericValue(char ch) Method

Java getNumericValue(char ch) method is a part of Character class. This method returns the int value of the specified. It returns -1 if the specified character does not have any int(numeric) value and -2 if the character has a numeric value that cannot be represented as a non-negative integer(for example a fraction or a decimal value).

Syntax:

Parameters:

The parameter passed is the character whose integer value is to be returned.

Returns:

Returns the numeric value of the specified character as a non-negative integer.

Example 1:

Here, the numerical non-negative int value of the characters is fetched by using getNumericValue() method.

The character A has int value : 10
The character G has int value : 16
The character M has int value : 22
The character 7 has int value : 7
The character Q has int value : 26

Example 2:

Here is a general example where the user can enter the input of his choice and get the desired output.

Enter the character
H
The character H has value : 17
************************************
Enter the character
4
The character 4 has value : 4

Live Example:

Here, you can test the live code example. You can execute the example for different values, even can edit and write your examples to test the Java code.

Похожие статьи