Skip to content

Added my day 5 code in Java #361

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions day5/Java/Pattern__1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* @date 14/10/2020
* @author Shashwat Gupta (shashwatxdevelop)
*/
import java.util.Scanner;

public class Pattern__1 {

public static void main(String[] args) {
int i,j,n;
Scanner sc = new Scanner (System.in);
n= sc.nextInt();
for(i=1; i<=n; i++)
{
for (j=1; j<=i;j++)
{
System.out.print(j+" ");
}
System.out.println();
}

}

}
23 changes: 23 additions & 0 deletions day5/Java/Pattern__2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* @date 14/10/2020
* @author Shashwat Gupta (shashwatxdevelop)
*/
import java.util.Scanner;
public class Pattern__2 {

public static void main(String[] args) {
int i,j,n, s=0;
Scanner sc = new Scanner (System.in);
n= sc.nextInt();
for (i=1; i<=n; i++)
{
for (j=1; j<=i; j++)
{
s=s+1;
System.out.print(s+" ");
}
System.out.println();
}

}

}
33 changes: 33 additions & 0 deletions day5/Java/Pattern__3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* @date 14/10/2020
* @author Shashwat Gupta (shashwatxdevelop)
*/
import java.util.Scanner;
public class Pattern__3 {

public static void main(String[] args) {
int i,j,n,a,b;
Scanner sc = new Scanner (System.in);
n= sc.nextInt();
for(i=1; i<=n; i++)
{
for(j=1; j<=i; j++)
{
System.out.print(j+" ");
}
System.out.println();
}


for (i=n-1; i>=1; i--)
{
for (j=1; j<=i; j++ )
{
System.out.print(j+" ");
}
System.out.println();
}

}

}

33 changes: 33 additions & 0 deletions day5/Java/Pattern__4.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* @date 14/10/2020
* @author Shashwat Gupta (shashwatxdevelop)
*/
import java.util.Scanner;
public class Pattern__4 {

public static void main(String[] args) {
int i,j,n;
Scanner sc =new Scanner (System.in);
n= sc.nextInt();


for (i=1; i<=n; i++)
{
for (j=n; j>i; j--)
{
System.out.print(" ");
}

for (j=i; j<=(2*i-1); j++)
{
System.out.print(j+" ");
}
for (j=(2*i-1) - 1; j>=i; j--)
{
System.out.print(j+" ");
}
System.out.println(" ");
}
}
}


29 changes: 29 additions & 0 deletions day5/Java/Pattern__5.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* @date 14/10/2020
* @author Shashwat Gupta (shashwatxdevelop)
*/
import java.util.Scanner;
public class Pattern__5 {

public static void main(String[] args) {
int i,j,k,n, p=1;
Scanner sc = new Scanner (System.in);
n= sc.nextInt();
for(i=1; i<=n;i++)
{
for (j=1; j<i; j++)
{
System.out.print(" ");
}
for (j=1; j<= (2*n-(2*i-1)); j++)
{
System.out.print("*");
}
System.out.println("");



}

}
}

148 changes: 147 additions & 1 deletion day5/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2157,10 +2157,156 @@ int main() {
eighth_pattern(num);
return 0;
}
```
/* @date 14/10/2020
* @author Shashwat Gupta (shashwatxdevelop)
*/
import java.util.Scanner;

public class Pattern__1 {

public static void main(String[] args) {
int i,j,n;
Scanner sc = new Scanner (System.in);
n= sc.nextInt();
for(i=1; i<=n; i++)
{
for (j=1; j<=i;j++)
{
System.out.print(j+" ");
}
System.out.println();
}

}

}
```
/* @date 14/10/2020
* @author Shashwat Gupta (shashwatxdevelop)
*/
import java.util.Scanner;
public class Pattern__2 {

public static void main(String[] args) {
int i,j,n, s=0;
Scanner sc = new Scanner (System.in);
n= sc.nextInt();
for (i=1; i<=n; i++)
{
for (j=1; j<=i; j++)
{
s=s+1;
System.out.print(s+" ");
}
System.out.println();
}

}

}
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here also

/* @date 14/10/2020
* @author Shashwat Gupta (shashwatxdevelop)
*/
import java.util.Scanner;
public class Pattern__3 {

public static void main(String[] args) {
int i,j,n,a,b;
Scanner sc = new Scanner (System.in);
n= sc.nextInt();
for(i=1; i<=n; i++)
{
for(j=1; j<=i; j++)
{
System.out.print(j+" ");
}
System.out.println();
}


for (i=n-1; i>=1; i--)
{
for (j=1; j<=i; j++ )
{
System.out.print(j+" ");
}
System.out.println();
}

}

}

```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same changes here

/* @date 14/10/2020
* @author Shashwat Gupta (shashwatxdevelop)
*/
import java.util.Scanner;
public class Pattern__4 {

public static void main(String[] args) {
int i,j,n;
Scanner sc =new Scanner (System.in);
n= sc.nextInt();


for (i=1; i<=n; i++)
{
for (j=n; j>i; j--)
{
System.out.print(" ");
}

for (j=i; j<=(2*i-1); j++)
{
System.out.print(j+" ");
}
for (j=(2*i-1) - 1; j>=i; j--)
{
System.out.print(j+" ");
}
System.out.println(" ");
}
}
}


```
/* @date 14/10/2020
* @author Shashwat Gupta (shashwatxdevelop)
*/
import java.util.Scanner;
public class Pattern__5 {

public static void main(String[] args) {
int i,j,k,n, p=1;
Scanner sc = new Scanner (System.in);
n= sc.nextInt();
for(i=1; i<=n;i++)
{
for (j=1; j<i; j++)
{
System.out.print(" ");
}
for (j=1; j<= (2*n-(2*i-1)); j++)
{
System.out.print("*");
}
System.out.println("");



}

}
}

```

### Have Another solution?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### Have Another solution?
### Have Another solution?


The beauty of programming lies in the fact that there is never a single solution to any problem.

In case you have an alternative way to solve this problem, do contribute to this repository (https://github.com/CodeToExpress/dailycodebase) :)
In case you have an alternative way to solve this problem, do contribute to this repository (https://github.com/CodeToExpress/dailycodebase) :)