In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Today, Xiaobian to share with you how to achieve string concatenation, integer addition and floating point addition related knowledge points, detailed content, clear logic, I believe that most people still know too much about this knowledge, so share this article for your reference, I hope you can learn something after reading this article, let's take a look at it.
Write a Java application program, read two strings from the keyboard, and overload three functions to realize the concatenation of the two strings, integer addition and floating point addition, and output the results. To handle the exception, prompt the user to package zyy.wxt.demo the input string that does not meet the requirements
Import java.util.Scanner;public class overload {public static void main (String [] args) {String S1 = null, S2 = null; Scanner sc = new Scanner (System.in); try {System.out.println ("Please enter the first string:"); S1 = sc.next (); System.out.println ("Please enter the second string:") S2 = sc.next ();} catch (Exception e) {System.out.println (e.getMessage ());} int i1 = Integer.parseInt (S1); int i2 = Integer.parseInt (S2); float F1 = Float.parseFloat (S1); float f2 = Float.parseFloat (S2); System.out.println (F1) System.out.println ("splicing result:" + strAdd (S1, S2)); System.out.println ("Integer result:" + strAdd (i1, i2)); System.out.println ("floating point result:" + strAdd (F1, f2));} public static String strAdd (String str1, String str2) {return str1 + str2;} public static int strAdd (int a, int b) {return a + b } public static String strAdd (float f11, float f22) {return String.valueOf (f11 + f22);}}
Running result
Please enter the first string:
one hundred and thirty two
Please enter the second string:
three hundred and twenty one
132.0
Stitching result: 132321
Integer result: 453
Floating point result: 453.0
These are all the contents of this article entitled "how Java implements string concatenation, integer addition and floating point addition". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
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.