如何在java中连接int值? [英] How to concatenate int values in java?

查看:30
本文介绍了如何在java中连接int值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下值:

int a=1; 
int b=0;
int c=2;
int d=2;
int e=1;

我如何连接这些值,以便我最终得到一个 10221 的字符串;请注意,将 a 乘以 10000、b 乘以 1000.....和 ​​e 乘以 1 将不起作用,因为 b=0,因此当我将值加起来时我会丢失它.

How do i concatenate these values so that i end up with a String that is 10221; please note that multiplying a by 10000, b by 1000.....and e by 1 will not working since b=0 and therefore i will lose it when i add the values up.

推荐答案

最简单(但有点脏)的方法:

The easiest (but somewhat dirty) way:

String result = "" + a + b + c + d + e

我不建议这样做,并且同意 Jon 的评论.添加那些额外的空字符串可能是简短和清晰之间的最佳折衷.

I don't recommend this and agree with Jon's comment. Adding those extra empty strings is probably the best compromise between shortness and clarity.

这篇关于如何在java中连接int值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆