首页 > 编程语言 > 详细

Java 2017.9.11 杨浩宁作业

时间:2017-09-13 00:56:47      阅读:257      评论:0      收藏:0      [点我收藏+]
//P61 2.15
import java.util.Scanner;

public
class test { public static void main(String[] args) { Scanner Hy=new Scanner(System.in); double x1,x2,y1,y2; System.out.println("请键入X1的值:"); x1 = Double.valueOf(Hy.nextLine()); System.out.println("请键入X2的值:"); x2 = Double.valueOf(Hy.nextLine()); System.out.println("请键入Y1的值:"); y1 = Double.valueOf(Hy.nextLine()); System.out.println("请键入Y2的值:"); y2 = Double.valueOf(Hy.nextLine()); System.out.println("两个点之间的距离是:"+ Math.pow((Math.pow((x2 - x1),2)+Math.pow((y2 - y1),2)),0.5)); } }

 

//P60 2.6

import java.util.Scanner;

public class test {
    public static void main(String[] args) {
        Scanner Hy=new Scanner(System.in);
        String Hyper;
        System.out.println("请输入一个0-1000的整数来求整数各位数的和");
        Hyper = Hy.nextLine();
        //方法1
        int test = Integer.valueOf(Hyper);
        if(test > 0 && test <= 1000) {
            int a = test % 2;
            int b = test / 10;
            int c = test / 100;
            System.out.println("总和为:" + (a + b + c));
        }
        else {
            System.out.println("不要皮!");
        }
        

        //方法2
        /*
        if(Integer.valueOf(Hyper) <= 1000) {
            int a = 0;
            for (int i = 0; i < Hyper.length(); i++) {
                a = a + Integer.valueOf(Hyper.substring(i, i + 1));
            }
            System.out.println(a);
        }*/

    }
}

 

Java 2017.9.11 杨浩宁作业

原文:http://www.cnblogs.com/Hyself/p/7512856.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!