Classic Loops in Java

Source: Internet
Author: User

1-1000 the sum of the number of conventions = itself

public class demo1{

public static void Main (string[] args) {

for (int i=1;i<1000;i++) {

int sum=0;

for (int j=1;j<i;j++) {

if (i%j==0) {

Sum +=j;

}


}

if (sum==i) {

System.out.println (i);

}

}

}

}

2. tab 5 rows 5 rows multiplied by 10 by 100 columns in turn

public class Demo19 {


public static void Main (string[] args) {

System.out.println ("N" + "\ T" + "10*n" + "\ T" + "100*n" + "\ T" + "1000*n");

for (int i=1;i<=5;i++) {

int sum=1;

for (int j=0;j<=3;j++) {

Sum*=10;

System.out.print (i*sum+ "\ t");

}

System.out.println ();

}

}


}

3. Enter a number, this number multiplication table

public class Demo2 {


public static void Main (string[] args) {

Scanner input=new Scanner (system.in);

System.out.println ("Please enter a number:");

int Num=input.nextint ();

for (int i = 1; I <=num; i++) {

for (int j = 1; J <=i; J + +) {

System.out.print (j+ "*" +i+ "=" +i*j);

System.out.print (' \ t ');

}

System.out.println ();

}

}


}


Classic Loops in Java

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.