Java loop structure (b) for the use of the For statement, the following example allows you to fully understand the For loop

Source: Internet
Author: User

Output

Import Java.util.scanner;public class Text10{public static void Main (string[] args) {Scanner sc=new Scanner (system.in); int I,j,n;n=sc.nextint (); for (i=1;i<=n;i++) {for (j=1;j<=n;j++) {System.out.print (i);} System.out.println ();}}}

Output Pyramid * No.



Import Java.util.scanner;public class Text11 {public static void main (string[] args) {    Scanner sc=new Scanner (System. in);    int i,j,n;    N=sc.nextint ();    for (i=1;i<=n;i++)    {for    (j=1;j<=n-i;j++)    System.out.print (");    for (j=1;j<=2*i-1;j++)    System.out.print (' * ');    System.out.println ();}}}    

Output



Import Java.util.scanner;public class Text12 {public static void main (string[] args) {    Scanner sc=new Scanner (System. in);    int i,j,n;    N=sc.nextint ();    for (i=1;i<=n;i++)    {for    (j=1;j<=i;j++)    System.out.print (j);    System.out.println ();}}}    

Output

Import Java.util.scanner;public class Text13 {public static void main (string[] args) {    Scanner sc=new Scanner (System. in);    int i,j,n;    N=sc.nextint ();    for (i=n;i>=1;i--)    {for      (j=1;j<=n-i;j++)      System.out.print (");      for (j=1;j<=i;j++)      System.out.print (j);      System.out.println ();}}}    

Output



Import Java.util.scanner;public class Text14 {public static void main (string[] args) {    Scanner sc=new Scanner (System. in);    int i,j,n;    N=sc.nextint ();    for (i=1;i<=n;i++)    {for    (j=n-i;j>=1;j--)    System.out.print (");    for (j=1;j<=2*i-1;j++)    System.out.print (i);    System.out.println ();    }    for (i=n-1;i>=1;i--)    {for    (j=n-i;j>=1;j--)    System.out.print (");    for (j=1;j<=2*i-1;j++)    System.out.print (i);    System.out.println ();}}}    


Output



Import Java.util.scanner;public class Text15 {public static void main (string[] args) {    Scanner sc=new Scanner (System. in);    int i,j,n;    N=sc.nextint ();    for (i=1;i<=n;i++)    {for    (j=n-i;j>=1;j--)    System.out.print (");    System.out.print (i);    for (j=2*i-3;j>=1;j--)    System.out.print (");    if (i!=1) System.out.print (i);    System.out.println ();    }    for (i=n-1;i>=1;i--)    {for    (j=n-i;j>=1;j--)    System.out.print (");    System.out.print (i);    for (j=2*i-3;j>=1;j--)    System.out.print (");    if (i!=1) System.out.print (i);    System.out.println ();}}}    

One- , two-, five-minute coins are exchanged for a dollar note, and the total number of coins required for redemption is -how many kinds of redemption methods are there? How many coins are used for each method of redemption?
public class Text16 {public static void main (string[] args) {    int x, y, Z;    for (x=0;x<=50;x++) for (    y=0;y<=50;y++) for (    z=0;z<=50;z++)    if (x+y+z==50) System.out.println ( "One point =" +x+ "two points =" +y+ "Five points =" +z ";}}



Java loop structure (b) for the use of the For statement, the following example allows you to fully understand the For loop

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.