由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 急!java 入门, 代码问题~~请各位好心人帮帮忙!
相关主题
比较简单的Java数据输入验证问题谁能说说Perl, Python, Tcl各自的优缺点?主要应用场合?
判断Python程序员水平的一个试题GNUPLOT怎么样画大小不同的点
RIch Hickey说design花了一个小时学习了python
C++: How to read until the end of file?这里的人用BOOST都是用来做什么?
why int** cannot convert to const int** ?3sum problem
C的问题,高手请指点[合集] 我也花了一小时读了一下python
c++ 中如何把str转换为float?what's the difference between tuple and pair in c++ code ?
请教关于float的精度和比较C++里面如何最方便的表示这个数组的数组?
相关话题的讨论汇总
话题: fn话题: sn话题: float话题: getfnsn话题: result
进入Programming版参与讨论
1 (共1页)
h*******9
发帖数: 68
1
刚刚开始学java,这周就要交网上作业,可是有个地方怎么试都不对,请各位好心人帮
帮忙!
我写了一个getFNSN(FN,SN);, 来模块化我的代码,可是应用起来下一行出来的总是原
始值,而不是用户的输入值,试来试去不知道怎样改才好。急死人了!
Result of adding 0.00 and 0.00 is 0.00.
部分相关代码如下:
{
public static void main(String[] args) {

float FN=0;
float SN=0;
{out.printf( "Please enter two numbers to add, separated by a space: ");

getFNSN(FN,SN);
out.printf("Result of adding %5.2f and %5.2f is %5.2f.n",FN, SN, FN+ SN);
}
static void getFNSN (float fn, float sn){
do {Scanner In = new Scanner(System.in);
try {
fn = In.nextFloat();
sn = In.nextFloat();
break;
}
catch (final InputMismatchException e) {
out.println("You have entered an invalid choice. Try again."
);
In.nextLine();
continue;
}
} while (true);}
}
结果:
What would you like to do? 1
Please enter two numbers to add, separated by a space: 2 3
Result of adding 0.00 and 0.00 is 0.00.
Press enter key to continue …
k**********g
发帖数: 989
2
float is a primitive type. It is called-by-value, so the caller's float
variable cannot be updated by the function even if the function modifies it.
(The function is modifying a copy of the value, not the caller's value.)
You can return the two values as a new float[2], a tuple, or a data object
that contains two float fields.
(A data object would be a reference type, which means that if the function
modify the data object's value, it will be seen by the caller.)
h*******9
发帖数: 68
3
Thank you for your answer! I got it a little bit. Could you give me an
example?
Thank you again!

it.

【在 k**********g 的大作中提到】
: float is a primitive type. It is called-by-value, so the caller's float
: variable cannot be updated by the function even if the function modifies it.
: (The function is modifying a copy of the value, not the caller's value.)
: You can return the two values as a new float[2], a tuple, or a data object
: that contains two float fields.
: (A data object would be a reference type, which means that if the function
: modify the data object's value, it will be seen by the caller.)

h*******9
发帖数: 68
4
我按照你说的又试了几次,终于弄出来了~~谢谢!

it.

【在 k**********g 的大作中提到】
: float is a primitive type. It is called-by-value, so the caller's float
: variable cannot be updated by the function even if the function modifies it.
: (The function is modifying a copy of the value, not the caller's value.)
: You can return the two values as a new float[2], a tuple, or a data object
: that contains two float fields.
: (A data object would be a reference type, which means that if the function
: modify the data object's value, it will be seen by the caller.)

1 (共1页)
进入Programming版参与讨论
相关主题
C++里面如何最方便的表示这个数组的数组?why int** cannot convert to const int** ?
Compile issuesC的问题,高手请指点
求助一个std::map的怪问题c++ 中如何把str转换为float?
几个C++的问题请教关于float的精度和比较
比较简单的Java数据输入验证问题谁能说说Perl, Python, Tcl各自的优缺点?主要应用场合?
判断Python程序员水平的一个试题GNUPLOT怎么样画大小不同的点
RIch Hickey说design花了一个小时学习了python
C++: How to read until the end of file?这里的人用BOOST都是用来做什么?
相关话题的讨论汇总
话题: fn话题: sn话题: float话题: getfnsn话题: result