12.1从输入对话框读入double型的华氏度,将其转换为摄氏度,并在消息对话框中显示结果。Celsius=(5/9)*(Fahrenheit-32)importjavax.swing.JOptionPane;publicclassExercise2_1{publicstaticvoidmain(String[]args){StringfahrenheitString=JOptionPane.showInputDialog(null,Enteratemperatureinfahrenheit:,Exercise2_1Input,JOptionPane.QUESTION_MESSAGE);doublefahrenheit=Double.parseDouble(fahrenheitString);doublecelsius=(5.0/9.0)*(fahrenheit-32);System.out.println(Thetemperatureis+celsius+inCelsius);System.exit(0);}}2.7编写程序将大写字母转换为小写字母,该字符在源代码ASCII中指定为直接量。publicclassExercise2_7{publicstaticvoidmain(String[]args){charuppercase='F';intoffset=(int)'a'-(int)'A';charlowercase=(char)((int)uppercase+offset);System.out.print(Thelowercaseletteris+lowercase);}}3.1(三角形有效性验证)读入三角形的三条边并确定输入是否有效。如果任意两条边和大于第三边则输入有效。importjavax.swing.JOptionPane;publicclassExercise3_1{publicstaticvoidmain(String[]args){StringnumberString=JOptionPane.showInputDialog(null,Enterthefirstedgelength(double),Exercise3_1Input,JOptionPane.QUESTION_MESSAGE);doubleedge1=Double.parseDouble(numberString);numberString=JOptionPane.showInputDialog(null,Enterthesecondedgelength(double),Exercise3_1Input,JOptionPane.QUESTION_MESSAGE);2//Convertstringtodoubledoubleedge2=Double.parseDouble(numberString);numberString=JOptionPane.showInputDialog(null,Enterthethirdedgelength(double),Exercise3_1Input,JOptionPane.QUESTION_MESSAGE);doubleedge3=Double.parseDouble(numberString);System.out.println(Canedges+edge1+,+edge2+,and+edge3+formatriangle?+((edge1+edge2edge3)&&(edge1+edge3edge2)&&(edge2+edge3edge1)));System.exit(0);}}4.1(千克转换成磅)编一个显示下列表格的程序(1千克为2.2磅)(1kilogram=2.2pounds)KilogramsPounds12.236.6……197433.4199437.8publicclassExercise3_8{publicstaticvoidmain(String[]args){System.out.println(kilograms\t\tpounds);System.out.println(-------------------------);intkilograms=1;for(inti=1;i=100;kilograms+=2,i++){System.out.println(kilograms+\t\t+kilograms*2.2);}}}4.18用嵌套的循环语句,分别编写程序打印下列图案。Pattern11121231234123453123456Pattern212345612345123412312/**PrintPatternI*/publicclassExercise3_23{publicstaticvoidmain(String[]args){for(inti=1;i=6;i++){for(intj=1;j=i;j++)System.out.print(j+);System.out.println();}}}//pattern2publicclasstest{publicstaticvoidmain(String[]args){for(inti=1;i=6;i++){for(intj=1;j=7-i;j++)System.out.print(j+);System.out.println();}}}5.1使用下述方法头,编写一个将大写字母转换成小写字母的方法。publicstaticcharupperCaseToLowerCase(charch)例如,upperCaseToLowerCase(‘B’)returns‘b’.publicclassExercise5_1{publicstaticvoidmain(String[]args){System.out.println(upperCaseToLowerCase('A'));System.out.println(upperCaseToLowerCase('e'));System.out.println(upperCaseToLowerCase('4'));System.out.println(upperCaseToLowerCase('R'));}publicstaticcharupperCaseToLowerCase(charc){if(c='A'&&c='Z'){return(char)(c+('a'-'A'));4}returnc;}}5.5(对三个数排序)编写以下方法,按升序显示三个数。publicstaticvoidsort(doubled1,doubled2,doubled3)publicclassExercise5_5{publicstaticvoidmain(String[]args){sort(3.4,5.4,2.2);}publicstaticvoidsort(doublenum1,doublenum2,doublenum3){if(num1num2){doubletemp=num1;num1=num2;num2=temp;}if(num2num3){doubletemp=num2;num2=num3;num3=temp;}if(num1num2){doubletemp=num1;num1=num2;num2=temp;}System.out.println(Thesortednumbersare+num1++num2++num3);}}6.1读入10个数字,计算它们的平均值并且找出有多少个数字在平均值之上。importjavax.swing.*;publicclassExercise5_1{publicstaticvoidmain(String[]args){double[]numbers=newdouble[10];doublesum=0;for(inti=0;inumbers.length;i++){Strings=JOptionPane.showInputDialog(Enteranumber:);numbers[i]=Double.parseDouble(s);sum+=numbers[i];}5doubleaverage=sum/10;intcountGreater=0;for(inti=0;inumbers.length;i++){if(numbers[i]average)countGreater++;}System.out.println(Thenumberofvaluesgreaterthantheaverageis+countGreater);System.exit(0);}}6.5读入10个数并且显示其中相互不同的数。提示:读入一个数,如果它是新数,则把它存储在数组中;如果数组中已有该数,则把它丢弃。输入结束后,数组中的数都是不同的数。publicclassExercise6_5{publicstaticvoidmain(String[]args){int[]numbers=newint[10];intsize=0;for(inti=0;inumbers.length;i++){Strings=JOptionPane.showInputDialog(null,Enteraninteger);intvalue=Integer.parseInt(s);booleanisInArray=false;for(intj=0;jsize;j++)if(numbers[j]==value){isInArray=true;break;}if(!isInArray){numbers[size]=value;size++;}}}7.1编写名为Rectangle的类表示矩形,这个类包括:两个double型的数据域widthandheight表示矩形的宽和高,它们的默认值都是1String类型的数据域color表示矩形的颜色,进一步假设所有矩形的颜色都是相同的,默认颜色为白色.无参构造方法创建默认矩形.一个构造方法创建指定widthandheight的矩形.6所有三个数据域的访问器方法和修改器方法;getArea()方法返回该矩形的面积.getPerimetet()方法返回它的周长.创建两个Rectangle对象。设计width5andheight15为第一个对象andwidth4.3andheight40.5为第二个对象。所有Rectangle对象的颜色为红色。显示两个对象的属性并求出它们的面积和周长。//Exercise7_1.java:CreatetheRectangleclasspublicclasstest{publicstaticvoidmain(String[]args){RectanglemyRectangle=newRectangle(5,40);System.out.println(Theareaofarectanglewithwidth+myRectangle.getWidth()+andheight+myRectangle.getHeight()+is+myRectangle.getArea());System.out.println(Thecoloris+myRectangle.getColor());RectangleyourRectangle=newRectangle(1.0,3.5);System.out.println(Theareaofarectanglewithwidth+yourRectangle.getWidth()+andheight+yourRectangle.getHeight()+is+yourRectangle.getArea());System.out.println(Thecoloris+yourRectangle.getColor());}}classRectangle{privatedoub