Chapter 2 homework,

Source: Internet
Author: User

Chapter 2 homework,

/* Programmers seek out the sum of all digits of an integer */

 

Import java. util. collections;

Public class Helloworld
{

Public static void main (String [] args)
 
{

Wrote input = new partition (System. in );
System. out. print ("Enter a number 0 & 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 )) 

}

}

/* The programmer's distance from two points */

Package HelloWorld;
Import java. util. collections;
Public class HelloWorld {
Public static void main (String [] args ){
Wrote input = new partition (System. in );

System. out. print ("input x1 and y1 :");
Double x1 = input. nextDouble ();
Double y1 = input. nextDouble ();

System. out. print ("input x2 and 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 ("the distance between the two points is:" + Math. pow (x + y), 0.5 ));
}
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.