jhy Sixth job

Problem 1: 5 on the basis of the job, and then creating a column type, comprising a rectangle, and the high volume of the three member variables, a constructor method to initialize member variables, and calculating the volume, for the bottom two functions method, main category input length, width, height, calculated cylinder volume, enter a new length, width, height, creating a new rectangle, the method using soled soled, the cylinder volume is calculated again.

Factorial package

package app.java;
public class Computer {
  int jc(int n) {
   int ji=1;
   int i;
   for(i=1;i<n;i++) {
    ji*=i;
   }
   return ji;
  }
}

Main class package

package app.java;
public class text {
 public static void main(String[] args) {
  // TODO Auto-generated method stub
    System.out.println("输入操作数n:");
    Computer computer=new Computer();
    int zongji=computer.jc(6);
    System.out.println(zongji);
 }
}
Problem 2: Design class called MyInteger, comprising: int type value a data field construction method, when the specified int value, object data created MyInteger field value and the access modifier isEven () and isOdd () method, if the current object is even or odd, class method returns true isPrime (MyInteger i), determines whether the specified value is a prime number, returns true MyInteger create objects in the main class, each class MyInteger verification method.

MyPoint class

ackage app.java;
{class myPoint public
  Double X;
     Double Y;
     public Double getX () {// build accessor
         return X;
     }
     public void setX (Double X) {// build modifier
         in this.x = X;
     }
     public Double getY () {
         return Y;
     }
     public void setY (Double Y) {
         this.y from Y =;
     }
     myPoint () {// constructor with no arguments
         X = 0;
         Y = 0;
     }
     public myPoint (Double X, Y Double) {/ / have reference constructor
         in this.x = X;
         this.y from Y =;
     }
     public static Double Distance (myPoint A1, B1 myPoint) {
         double x1=a1.getX();
         double x2=b1.getX();
         double y1=a1.getY();
         double y2=b1.getY();
         return Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
}

Test the main class

package app.java;
import java.util.Scanner;
public class Text1 {
 private static Scanner reader;
 static void main public (String [] args) {
  // the TODO Auto-Generated Method Stub
  Double X1, Y1, X2, Y2;
  Reader = new new Scanner (the System.in);
        System.out.println ( "Enter first cross coordinate value ");
        X1 = reader.nextDouble ();
        System.out.println (" ordinate value of a first input ");
        Y1 = reader.nextDouble ();
        System.out.println (" enter the second abscissa value ");
        X2 = reader.nextDouble ();
        System.out.println (" input of the second ordinate value ");
         Y2 = reader.nextDouble ();
         myPoint new new P1 = myPoint (X1, Y1);
         myPoint new new myPoint P2 = (X2, Y2);
         System.out.println ( "distance between two points is:" + Mypoint.distance (p1, p2 )); // output
 }

Guess you like

Origin www.cnblogs.com/jianghongyan1/p/11567301.html