java怎样运行得出 y = 15.454; //y是个整型数 w = 456; //w是个双精度数

来源:百度知道 编辑:UC知道 时间:2024/06/01 01:24:47
public class Assign {
public static void main (String args []) {
// declare integer variables
int x, y;
// declare and assign floating point
float z = 3.414f;
// declare and assign double
double w = 3.1415;
// declare and assign boolean
boolean truth = true;
// declare character variable
char c;
// declare String variable
String str;
// declare and assign String variable
String str1 = "bye";
// assign value to char variable
c = 'A';
// assign value to String variable
str = "Hi out there!";
// assign values to int variables
x = 6;
y = 1000;
}
}

全局变量中重新定义y的类型,因为局部变量中y已经被定义为整型

运算在哪里?上面的程序中没有找到。从上面的程序看y定义的是int型的,y = 15.454;的话,程序应该会报错误的,中途改变变量的类型好像也不可能,不过可以在y的生命周期结束后再重新定义,那就没问题了。

不明白你的代码,也没有输入代码,你怎么知道x,y的值

你的程序不完整吧,叫人家怎么回答,程序中哪有变量w?赋了一堆值,什么运算也没做

很抱歉,你的程序不完整!方法是什么?