如何使用Java将变量连接成一个变量 [英] how to concatenate variables into a variable with java

查看:55
本文介绍了如何使用Java将变量连接成一个变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将几个变量连接成一个字符串变量,但是我无法使其正常工作.当我编译时,它说不是声明"和;预期".

I would like to concatenate a few variables into a string variable but I am unable to get it to work. When I compile it says "not a statement" and "; expected."

float a = 1;
float b = 2;
String resW;

我的目的是连接"a"和"b"并将其分配给resW.

My purpose is to concatenate "a" and "b" and assign it to resW.

resW = a " + " b;

我的最终目标是像这样使用resW ...

My ultimate goal is to use resW as such...

System.out.println(resW);
bufferedWriter.write(resW);

它应该以"1 + 2"的格式保存到文件中.我不知道如何正确执行此操作,甚至无法做到这一点.

It should save to a file in the format of "1 + 2". I don't understand how to do this properly or if this is even possible.

推荐答案

String resW = a + " + " + b;

尝试一下.

这篇关于如何使用Java将变量连接成一个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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