Java课堂例子验证
项目一:
(一)名称:EnumTest
(二)源代码
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};
(三)截图
项目二:
(一)名称:Addition
(二)源代码
import javax.swing.JOptionPane;
public class Addition {
public static void main( String args[] )
{
String firstNumber,
secondNumber;
int number1,
number2,
sum;
firstNumber =
JOptionPane.showInputDialog( "Enter first integer" );
secondNumber =
JOptionPane.showInputDialog( "Enter second integer" );
number1 = Integer.parseInt( firstNumber );
number2 = Integer.parseInt( secondNumber );
sum = number1 + number2;
JOptionPane.showMessageDialog(
null, "The sum is " + sum, "Results",
JOptionPane.PLAIN_MESSAGE );
System.exit( 0 );
}
}
(三)截图
项目三:
(一)名称:class TestDouble
(二)源代码
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));
}
}
(三)截图
项目四:
(一)名称 :Test
(二)源代码
public class Test1 {
public static void main(String[] args) {
int intValue=100;
long longValue=intValue;
double doubleValue=1234567890;
float floatValue=(float)doubleValue;
System.out.println(floatValue);//1.23456794E9
int X=100;
int Y=200;
System.out.println("X+Y="+X+Y);
System.out.println(X+Y+"=X+Y");
doNotRunme();
String string="";
double d1=1000.123;
double d2=1000.123;
if(Math.abs(d2-d1)<1e-10){
}
//System.out.println(string);
}
public static void doNotRunme()
{
doNotRunme();
}
}
(三)截图