ppt页数 37 44 46 50 52 54 56 59 62
一
1.问题
2.源代码
package test;
enum Size{SMALL,MEDIUM,LARGE};
public class test {
public static void main(String[] args) {
Size s=Size.SMALL;
Size t=Size.LARGE;
System.out.println(s==t);
System.out.println(s.getClass().isPrimitive());
Size u=Size.valueOf("SMALL");
System.out.println(s==u); ֵ
for(Size value:Size.values()){
System.out.println(value);
}
}
}
3.运行截图
4.过程解析
枚举类型有多重赋值方法,枚举类型不是八大基本类型。枚举类型方法values()是其所有值的集合;
二
1.问题
三
1.问题
2.源代码
package test;
//An addition program
import javax.swing.JOptionPane; // import class JOptionPane
public class test {
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
// 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;
// display the results
JOptionPane.showMessageDialog(
null, "The sum is " + sum, "Results",
JOptionPane.PLAIN_MESSAGE );
System.exit( 0 ); // terminate the program
}
}
3.结果
四
1.问题
2.源代码
package test;
public class test {
public static String value = "外层";
public static void main( String args[] )
{
String value = "内层";
System.out.println(value);
System.out.println(slim.value);
}
public static class slim
{
public static String value = "类中";
}
}
3.结果和解析
内层会覆盖外层 在内层调用类中变量 会覆盖内层。总而言之 越内越先
五
1.问题