public float area(double r) {
return (float)(myPI*r*r); } }
3. 定义类A,在其中定义一个final变量myPI,其类型为float,值为3.1416;类A中还定义一个final方法 m1(float r),该方法返回值类型为float,功能是求半径为r的圆的周长(公式为:2?r)。再定义类A的子类B,B为final类,其中定义一个返回值类型为void的方法 m2(float r),功能是先调用父类的方法m1( )求半径为r的圆的周长并输出计算结果,然后输出同一个圆的面积(公式为:?r2)。请编写一个Application ,利用类B计算并输出半径为5的圆的周长和面积。 @程序
public class Class1 {
static B x=new B( );
public static void main(String[ ] args) {
x.m2(5); } }
class A {
final float myPI=3.1416f;
public final float m1(float r) { return 2*myPI*r; } }
final class B extends A {
public void m2(float r) {
System.out.println(\半径为\的圆的周长=\ System.out.println(\半径为\的圆的面积=\ } }
4.编写应用程序,功能为:从命令行传入一个包含十个字符的字符串,把该字符串与程序中给定的字符串\依次比较,统计两个串中对应字符相等的数目。然后输出命令行输入的字符串,并把两个串中对应字符不相等的字符替换为'@'后生成的新串输出,最后输出两个串中相等字符的数目。 @程序
public class Class1 {
public static void main(String args[]) throws IOException {
if(args[0].length()<10) System.out.print(\else
}
}
{ }
String str=new String(\int n=0;
System.out.print(\for (int x=0;x System.out.print(\  \  System.out.println();  System.out.print(\ Student answer:\for (int x=0;x System.out.println( );  System.out.println(\ if (args[0].charAt(x)==str.charAt(x)) {  n++; System.out.print(\  \}  System.out.print(\  \     else    5. 请编写一个Application实现如下功能:接受命令行中给出的一个字母串,先将该串原样输出,然后判断该串的第一个字母是否为大写,若是大写则统计该串中大写字母的个数,并将所有大写字母输出;否则输出信息串”第一个字母不是大写字母!”。 @程序  public  class Class1 {  public  static  void  main(String  args[])  {          int  count=0;   if(args.length!=0)   {    System.out.println(args[0]);    if((int)args[0].charAt(0)>=65 && (int)args[0].charAt(0)<=90)    {  for(int i=0;i                         { System.out.print(args[0].charAt(i));      Count++;     }                 System.out.println( );                  System.out.println(―共有 ‖+count+‖ 个大写字母。‖);    }    else   System.out.println(\第一个字母不是大写字母!\  }    }    }  else   System.out.println(\请给出命令行参数!\ 练习7(5)  掌握:命令行传参数。   1.请编写一个实现如下功能的Application:比较命令行中给出的两个整数是否相等,并根据比较结果显示\相等\或\不相等\。 public  class  Class1 {  public  static  void  main (String[]  args)  {   int  x,y;    String  str=\  if(args.length < 2)   {    System.out.println(\请在命令行输入两个参数\   System.exit(-1);   }       x=Integer.parseInt(args[0]);   y=Integer.parseInt(args[1]);   if (x==y) str=\命令行输入的两个参数相等\  else str=\命令行输入的两个参数不相等\  System.out.println( str );  } }  2.编写一个Application程序,比较命令行中给出的两个字符串是否相等,并输出比较的结果。 import  java.io.*; public class Class1 {  public static void main (String[] args)  {   if( args.length < 2 )   {    System.out.println( \ string2\   System.exit(-1);   }   if(args[0].equals(args[1]))    System.out.println( args[0]+\和 \相等 \  else    System.out.println( args[0]+\和 \不等 \ } }  3.从命令行传入3个整数,求3个整数的和、积、最大值、最小值。 public class Class1 {   public static void main (String[] args)  {   int n=args.length;   if(n<3)    System.out.println(\请输入三个整数!\  else   {    int a,b,c;    a=Integer.parseInt(args[0]);    b=Integer.parseInt(args[1]);    c=Integer.parseInt(args[2]);    System.out.println(\和:\   System.out.println(\积:\   System.out.println(\最大值:\   System.out.println(\最小值:\  }  } }  4.请编写一个Application实现如下功能:通过命令行中给出的float型参数x, 和int型参数y(如果参数少于两个,给出提示后退出系统),调用Math类中的方法求x的y次方并输出。 import  java.io.*; public  class  Class1 {  public  static  void  main (String[]  args)  {   int  x,y;   String  str=\  if(args.length < 2)   {    System.out.println(\ number2\   System.exit(-1);   }       x=Float.valueOf(args[0]).floatValue( );   y=Integer.parseInt(args[1]);     str=str+x+\的 \次方 = \  System.out.println( str );  } }  5.编写Application,求从命令行传入任意多个整数的最大值、最小值、平均值。 public class Class1 {  public static void main (String[] args)  {   int n=args.length;   if(n==0)     System.out.println(\  else   {    int x[]=new int[n];    for(int i=0;i     static int ArrayMax( int array[] )     {        int max = array[0];        for( int i =1; i < array.length; i++)    {     if ( array[i] > max )     {      max = array[i];     }    }        return max;     }      static int  ArrayMin( int  array[] )     {        int min = array[0];        for( int i =1; i < array.length; i++)           if ( array[i] < min ) min = array[i];        return min;     }  static int  ArrayAve( int  array[] )     {        int sum=0;       for( int i =0; i < array.length; i++)           sum+=array[i];        return sum/array.length;     } }  6.请编写一个实现如下功能的Application:从命令行依次取三个参数 x, y, op 做算术运算,其中 x, y为 int 型数据,op 为运算符(+、-、×、÷ 之一),请显示 x  op  y 的结果。 public class  MainParameters {  public  static  void  main(String  args[])  {   int  x, y;   char  op;   String  str=\