标签:
枚举类型
public class EnumTest {
public static void main(String[] args) {
Size s=Size.SMALL;
Size t=Size.LARGE;
//s和t引用同一个对象?
System.out.println(s==t); //
//是原始数据类型吗?
System.out.println(s.getClass().isPrimitive());
//从字符串中转换
Size u=Size.valueOf("SMALL");
System.out.println(s==u); //true
//列出它的所有值
for(Size value:Size.values()){
System.out.println(value);
}
}
}
enum Size{SMALL,MEDIUM,LARGE}
;
精度损失
public class TestDouble {
public static void main(String args[]) {
System.out.println("0.05 + 0.01 = " + (0.05 + 0.01));
System.out.println("1.0 - 0.42 = " + (1.0 - 0.42));
System.out.println("4.015 * 100 = " + (4.015 * 100));
System.out.println("123.3 / 100 = " + (123.3 / 100));
}
}
int X=100;
int Y=200;
System.out.println("X+Y="+X+Y);
System.out.println(X+Y+"=X+Y");
解释:
加号用于拼接字符串以及求和之用
当左右两边连接的都是非数字类型时,则为连接符;
当一边是数值类型,另一边是非数值类型时,则为连接符;
当两边都是数值类型时,则为运算符,即相加求和的作用。
课后作业
import javax.swing.JOptionPane; // import class JOptionPane
public class Addition {
public static void main( String args[] )
{
String firstNumber, // first string entered by user
secondNumber; // second string entered by user
int number1, // first number to add
number2, // second number to add
sum,// sum of number1 and number2
jian,//cha
cheng; //cheng ji
double chu; // shang
// read in first number from user as a string
firstNumber =
JOptionPane.showInputDialog( "Enter first integer" );
// read in second number from user as a string
secondNumber =
JOptionPane.showInputDialog( "Enter second integer" );
// convert numbers from type String to type int
number1 = Integer.parseInt( firstNumber );
number2 = Integer.parseInt( secondNumber );
// add the numbers
sum = number1 +number2;
jian=number1-number2;
cheng=number1*number2;
chu=number1/number2;
// display the results
JOptionPane.showMessageDialog(
null, "两者相加" + sum+"\n相减"+jian+"\n相乘"+cheng+"\n相除"+chu, "Results",
JOptionPane.PLAIN_MESSAGE );
System.exit( 0 ); // terminate the program
}
}、
标签:
原文地址:http://www.cnblogs.com/myblog-2015/p/4859691.html