Java作业二(2017-9-18)

/*程序员龚猛,求整数各个位上的和*/

 

import java.util.Scanner;

public class Helloworld
{

 public static void main(String[] args)
 
 {
  
    Scanner input=new Scanner(System.in);
         System.out.print("Enter a number 0 and 1000 :");
         int number =input.nextInt();
         int bit=number%10;
         number=number/10;
         int ten=number%10;
         number=number/10;
         int kil=number%10;
         System.out.println("The sum of the digits is "+(bit+ten+kil))  

}

}

/*程序员龚猛,两点的距离*/

package HelloWorld;
import java.util.Scanner;
public class HelloWorld {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);

System.out.print("输入x1和y1:");
double x1 =input.nextDouble();
double y1 =input.nextDouble();

System.out.print("输入x2和y2:");
double x2 =input.nextDouble();
double y2 =input.nextDouble();

double x =Math.pow((x2 - x1),2);
double y =Math.pow((y2 - y1),2);

System.out.println("两个点之间的距离是:"+ Math.pow((x+y),0.5));
  }
}

 

posted @ 2017-09-18 12:42  So.cool  阅读(172)  评论(0编辑  收藏  举报