Posts

Check Number Sequence

  You are given S, a sequence of n integers i.e. S = s1, s2, ..., sn. Compute if it is possible to split S into two parts : s1, s2, ..., si and si+1, si+2, ….., sn (0 <= i <= n) in such a way that the first part is strictly decreasing while the second is strictly increasing one. Note : We say that x is strictly larger than y when x > y. So, a strictly increasing sequence can be 1 4 8. However, 1 4 4 is NOT a strictly increasing sequence. That is, in the sequence if numbers are decreasing, they can start increasing at one point. And once the sequence of numbers starts increasing, they cannot decrease at any point further. Sequence made up of only increasing numbers or only decreasing numbers is a valid sequence. So, in both the cases, print true. You just need to print true/false. No need to split the sequence. Sample Input 1 : 5 9 8 4 5 6 Sample Output 1 : true import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner s = new Scanner (Sys

Diamond of Stars

Image
  Pattern for N = 5 import java.util.Scanner; public class DiamondOfStars { public static void main(String[] args) { Scanner s = new Scanner(System.in); int n= s.nextInt(); int f=n/2; int l=n-f; int sp=f; for(int i=1;i<=f;i++) { for(int k=1;k<=sp;k++) { System.out.print(" "); } sp--; for(int j=1;j<=2*i-1;j++) { System.out.print("*"); } System.out.println(); } int space = 1; for(int i=l;i>=1;i--) { for(int k=1;k<space;k++) { System.out.print(" "); } space++; for(int j=1;j<=2*i-1;j++) { System.out.print("*"); } System.out.println(); } } }

Triangle of Numbers

Image
Pattern for N = 4 import java.util.Scanner; public class TriangleOfNum { public static void main(String[] args) { Scanner s = new Scanner(System.in); int n= s.nextInt(); int p=0; int q=0; for(int i=1;i<=n;i++) { for(int j=1;j<=n-i;j++) { System.out.print(" "); } p=i; for(int k=1;k<=i;k++) { System.out.print(p); p++; } q=2*i-2;             for(int d = i-1; d>=1;d--)             {                         System.out.print(q);             q--;             } System.out.println(); } } }

Star Pattern

Image
  Pattern for N = 4 import java.util.Scanner; public class StarPattern { public static void main(String[] args) { Scanner s = new Scanner(System.in); int n= s.nextInt(); for(int i=1;i<=n;i++) { for(int j=1;j<=n-i;j++) { System.out.print(" "); } for(int k=1;k<=2*i-1;k++) { System.out.print("*"); } System.out.println(); } } }

Inverted Number Pattern

  Pattern for N = 4 4444 333 22 1 import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k; for(int i=n; i>=1;i--) { for(int j=1; j<=i;j++) { System.out.print(i); } System.out.println(); } } }

Mirror Image Number Pattern

Image
  Pattern for N = 4 import java.util.Scanner; public class MirrorImagePattern { public static void main(String[] args) { Scanner s = new Scanner(System.in); int n= s.nextInt(); for(int i=1;i<=n;i++) { for(int j=1;j<=n-i;j++) { System.out.print(" "); } for(int k=1;k<=i;k++) { System.out.print(k); } System.out.println(); } } }

Interesting Alphabets Pattern

  Pattern for N = 5 E DE CDE BCDE ABCDE import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); for(int i=n; i>=1;i--) { char c = (char)('A' + i - 1); for(int j=i ;j<=n;j++) { System.out.print(c);                c = (char)(c + 1); } System.out.println(); } } }