Posts

Showing posts from May, 2016

Number Pattern programs in java

Simple number pattern program in java 1) Enter a number : 5 1 12 123 1234 12345 import java.util.Scanner; public class Pattern1 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System .out.println( "Enter a number :" ); int n = scanner.nextInt(); for ( int i = 1; i <= n; i++) { for ( int j = 1; j <= i; j++) { System .out.print(j); } System .out.println(); } } } 2) Enter a number : 5 12345 1234 123 12 1 import java.util.Scanner; public class Pattern2 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("Enter a number :"); int n = scanner.nextInt(); for (int i = n; i > 0; i--) { for (int j = 1; j <= i; j++) { System.out.print(j); } System.out.println(); } } } 3) Enter a number :5     1    1 2   1 2 3  1 2 3 4 1 2 3 4 5  import java.util.Scanner; public class Pa...

pattern related programs in java

Simple triangle star pattern 1) Enter a number : 4     *     * *     * * *     * * * * import java.util.Scanner; public class Pattern1 { public static void main( String [] args) { Scanner scanner = new Scanner ( System . in ); System . out .println("Enter a number :"); int n = scanner.nextInt(); for ( int i = 1; i <= n; i++) { for ( int j = 1; j <= i; j++) { System . out .print("*"); } System . out .println(); } } } 2) Enter a number : 4 * * * * * * * * * *  import java.util.Scanner; public class Pattern2 { public static void main( String [] args) { Scanner scanner = new Scanner ( System . in ); System . out .println("Enter a number :"); int n = scanner.nextInt(); for ( int i = n; i > 0; i--) { for ( int j = 0; j < i; j++) { System . out .print("*"); } System . out .println(); } } } 3) Enter a number :4           ...