2、
import javax.swing.JOptionPane; public class T3_2 {
public static void main(String args[]) {
String Str;
int i=1,a,a1,a2,a3,a4,a5;
Str=JOptionPane.showInputDialog(\请输入一个5位数的正整数:\ (4) =Integer.parseInt(Str); if(a<10000 || a>99999)
Str=\请输入正确的五位数。\ else {
(5) =a/10000; a2=(a/1000); a3=(a/100); a4=(a/10); a5=a;
if(a1==a5 && a2==a4)
Str=a+\这个数是回文。\ else
(6) =\这个数不是回文。\ }
JOptionPane.showMessageDialog(null,Str);
} } 3、
import javax.swing.*; public class T3_3 {
public static void main(String args[]) {
int a,b,c,ma3;
a=accept( ); b=accept( ); (7) =accept( ); ma3=max3(a,b,c);
JOptionPane.showMessageDialog(null,ma3); }
public static int (8) ( ) {
String str; int x;
str=JOptionPane.showInputDialog(\请输入一个整数\ x=Integer.parseInt(str); return x;
共 12 页 第 5 页
}
static int max3(int x,int y,int z) {
int ma;
ma=Math.max(x,y);
(9) =Math.max(ma,z); return ma; } }
4、
import javax.swing.*; public class T3_4 {
public static void main(String args[]) {
int x=0,m;String str;
(10) =JOptionPane.showInputDialog(\请输入一个数\ x=Integer.parseInt(str); for(m=2;m if(x%m==0) (11) ; } if(m==x) str=str+ \ else (12) =str+ \ JOptionPane.showMessageDialog(null,str); } } 5、 import javax.swing.*; public class T3_5 { public static void main(String args[]) { int x,a,b,c;String (13) ; sx=JOptionPane.showInputDialog(\请输入一个三位正整数\ x=Integer.parseInt(sx); while(x<100 (14) x>999) { sx=JOptionPane.showInputDialog(\请重新输入一个三位正整数\ x=Integer.parseInt(sx); 共 12 页 第 6 页 } a= (15) ; b=x/10-a*10; c=x; JOptionPane.showMessageDialog(null,c+\ } } 分数 四、编程题,请写出完整的程序。(共15分) 1、(6分)编程求1? 评卷人 111?? ... ?的值并输出,其中, n≥2。 23n2、(9分)定义一个打印机类Printer,要求如下: ? 私有属性weight,代表打印机的重量,数据类型为float ? 私有属性typ,代表打印机的型号,数据类型为String ? 构造方法public Printer(),将重量和型号初始化为默认值 ? 构造方法public Printer(float w, String t),将重量和型号初始化为w、v、t ? 公有方法getWeight ( ),用于获取打印机的重量 ? 公有方法setWeight ( ),用于设置打印机的重量 ? 公有方法getType( ),用于获取打印机的型号 ? 公有方法setType( ),用于设置打印机的型号 ? 公有方法disp ( ),用于显示打印机的重量和型号 共 12 页 第 7 页 共 12 页 第 8 页
相关推荐: