Java code: Use for loop sum, courtship number and, find odd and, print Narcissus number, statistics narcissus number

Source: Internet
Author: User

use for loop sum, courtship number and, odd sum, print narcissus number, statistics narcissus number
Package loop;

public class For1 {
public static void Main (string[] args) {
int sum=0;
for (int x=0;x<=100;x++) {
Sum=sum+x;
}
System.out.println ("within 100 (including 100) integers and:" +sum);
System.out.println ("-----------------------------------------");

    int sumEven=0;    for(int y=0;y<=100;y++) {        if(y%2==0) {            sumEven=sumEven+y;          }       }    System.out.println("100以内(含100)偶数和:"+sumEven);    System.out.println("-----------------------------------------");    int sumOdd=0;    for(int m=0;m<=100;m++) {        if(m%2!=0) {            sumOdd=sumOdd+m;            }           }    System.out.println("100以内(含100)奇数和:"+sumOdd);    System.out.println("-----------------------------------------");    int number=0;    System.out.println("输出所有的水仙花数:");       for(int f=100;f<1000;f++) {        int g=f%10;        int s=f/10%10;        int b=f/10/10%10;        if(f==g*g*g+s*s*s+b*b*b) {            System.out.println(f);            number=number+1;        }           }    System.out.println("水仙花数共有:"+number+"个");       System.out.println("-----------------------------------------");            }

}

Java code: Use for loop sum, courtship number and, find odd and, print Narcissus number, statistics narcissus number

Related Article

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.