To find the prime number between 1~50 (terminating it with a labeled break statement)

Source: Internet
Author: User

Tag: Make it terminate with a labeled break statement

Public class c3_18{     public static void main (String[]  args)     {             Int n=0,m,j,i;        p1:for (i=3;i<=100;i+=2)//outer loop, front with label         {             m= (int) math.sqrt ((double) i);                         for (j=2;j<=m;j++)//inline loop               {                               if ((i%j) ==0)  break;                              if (i==51)  break  p1;//the end of the loop             }//inline loop that the label P1 points to when the condition is established             if (j>=m+1)              {                             if (n%6==0)  system.out.print ("\ n");//Line break control                  system.out.print (i+ "  ");                 n++;             }        }//outer loop ends     }}

Run results

650) this.width=650; "src=" http://img.blog.csdn.net/20150723163145420 "alt=" here write a picture describing "title=" "/>


This article is from the "Sanghaidan blog column" blog, please be sure to keep this source http://10602803.blog.51cto.com/10592803/1683069

To find the prime number between 1~50 (terminating it with a labeled break statement)

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.