-
Notifications
You must be signed in to change notification settings - Fork 153
Added my day 5 code in Java #361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
5bc98bb
0d03a86
1a15adb
58ca360
58c6ddd
2bdd8b6
b81b6d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* @date 25/09/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(); | ||
} | ||
|
||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,23 @@ | ||||||||
/* @date 25/09/2020 | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
* @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(); | ||||||||
} | ||||||||
|
||||||||
} | ||||||||
|
||||||||
} |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,33 @@ | ||||||||
/* @date 25/09/2020 | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
* @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(); | ||||||||
} | ||||||||
|
||||||||
} | ||||||||
|
||||||||
} | ||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* @date 25/09/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(" "); | ||
} | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,29 @@ | ||||||||
/* @date 25/09/2020 | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
* @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(""); | ||||||||
|
||||||||
|
||||||||
|
||||||||
} | ||||||||
|
||||||||
} | ||||||||
} | ||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2158,7 +2158,152 @@ int main() { | |||||||||
return 0; | ||||||||||
} | ||||||||||
``` | ||||||||||
/* @date 25/09/2020 | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Please add empty line after previous code |
||||||||||
* @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 25/09/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(); | ||||||||||
} | ||||||||||
|
||||||||||
} | ||||||||||
|
||||||||||
} | ||||||||||
``` | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here also |
||||||||||
/* @date 25/09/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(); | ||||||||||
} | ||||||||||
|
||||||||||
} | ||||||||||
|
||||||||||
} | ||||||||||
|
||||||||||
``` | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same changes here |
||||||||||
/* @date 25/09/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 25/09/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? | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
The beauty of programming lies in the fact that there is never a single solution to any problem. | ||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.