In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces what is the variable type conversion in Java. It is very detailed and has certain reference value. Friends who are interested must finish reading it.
/ * Type conversion is divided into the following cases 1. Integer type conversion 2. Floating point type conversion 3. Boolean type conversion 4. Character type conversion * / public class TypeConvert {public static void main (String [] args) {byte a1room1; int b1room2; / / small integer type converted to large integer type, direct conversion b1rooma1; System.out.println (b1); byte a2room1; int b2room2; int b3room128 / / converting a large integer type to a small integer type requires a cast and may lose precision. The high position will be removed. A2 = (byte) b2; a2 = (byte) b3; System.out.println (a2); byte c1; float c2 to 10.3f; / / integer to floating point, direct conversion to c2xc1; System.out.println (c2); byte D1 to 1; float d2 to 10.3f Float d3 = 128.2f; / / floating-point type conversion directly removes the decimal part, requires forced type conversion, and may lose precision D1 = (byte) D2; D1 = (byte) D3; System.out.println (D1) / / Boolean types cannot be converted to other types, and other types cannot be converted to Boolean types boolean e1roomtruth; / / E1 = (boolean) 1; char f1examples; int f2examples 1; char f3examples examples; int f4='b'+1 Char f5 integer type can be converted to character type, which requires forced type conversion, and integer type can also be converted to character type. The conversion rule is ACSII code table F1 = (char) f2; f2roomf3; System.out.println (f1); System.out.println (f2) System.out.println (f4); System.out.println (f5); / / string concatenation + conversion String str= "hello"; String str2=str+1; String str3=str+2.5; String str4=str+true; String str5=str+'F' / / string plus other basic types are automatically converted to string concatenation System.out.println (str2); System.out.println (str3); System.out.println (str4); System.out.println (str5);}} / * Summary: 1. Type conversion decimal to large value conversion byte
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.