Welcome back to my blog! You saw how to print "Hello, Java" using Eclipse in the previous post.
In this post you will learn how to draw the following design in Java using Eclipse:
*
* *
* * *
* * * *
* * * * *
public class Design {
public static void main(String[] args) {
for (int a=0;a<=5;a++)
{
for(int b=0;b<a;b++)
{
System.out.print("* ");
}
System.out.println();
}
}
}
Note: You can change the number of rows by changing the value of integer a. For example, you can change the number of rows from 5 to 10 by making (int a=10; a<=10;a++) in the first for loop.
The area inside the red rectangle is the place where the output of your program is shown.
Congratulations!! Feel like a programmer!!
In this post you will learn how to draw the following design in Java using Eclipse:
*
* *
* * *
* * * *
* * * * *
Step #1. Open Eclipse and enter the directory where you want to save your work as shown in the picture below:
Step #2. Select File>New>Java Project.
Step #3. Enter the project name in Project name and then click on Next.
Step #4. Click on Finish.
Step #5. You will see a folder named "src" under the project name.
Step #6. Right click on the folder "src">New>Class.
Step #7. Enter the name of the class and click on Finish.
Step #8. You will see a screen like this:
Step #9. Write the following code:
public class Design {
public static void main(String[] args) {
for (int a=0;a<=5;a++)
{
for(int b=0;b<a;b++)
{
System.out.print("* ");
}
System.out.println();
}
}
}
Note: You can change the number of rows by changing the value of integer a. For example, you can change the number of rows from 5 to 10 by making (int a=10; a<=10;a++) in the first for loop.
Step #10. Run your code by clicking on the Run button as shown in the picture below:
Step #11. Hurrah!!! The output of your program is ready!!
The area inside the red rectangle is the place where the output of your program is shown.
Congratulations!! Feel like a programmer!!
Comments
Post a Comment