Exercises on functions in Java Learning

Source: Internet
Author: User

/*
1. Define a function to print the rectangle.
2. Define a function that prints the function of the 99 multiplication table.
*/
Class FunctionTest {
public static void Main (string[] args)
{
Draw (5,6);
Printhr ();
Draw (7,9);
Printhr ();
Print99 ();
}
/*
Define a function that prints the 99 multiplication table function
*/
public static void Print99 ()
{
for (int x=1;x<=9;x++)
{
for (int y=1;y<=x;y++)
{
System.out.print (y+ "*" +x+ "=" +y*x+ "\ t");
}
System.out.println ();
}
}
/*
Defines a feature that is used to print rectangles.
Ideas:
1, determine the result: no, because direct printing, so the return value type is void
2. Is there any unknown content? There are, two, because the rows and columns of the rectangle are indeterminate
*/
public static void Draw (int row,int col)
{
for (int x=0;x<row;x++)
{
for (int y=0;y<col;y++)
{
System.out.print ("*");
}
System.out.println ();
}
}
public static void Printhr ()
{
System.out.println ("----------");
}

}

Exercises on functions in Java Learning

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.