Pattern Program in java alphabet pattern, Number pattern Program.
Write a program to print the Alphabet pattern.
Input
Format:
Input consists of a single integer which corresponds to the number of rows..
Output
Format:
Refer sample output.
Sample
Input:
5
Sample
Output:
E
ED
EDC
EDCB
EDCBA
@MRProgrammer89
package Mr_Programmer;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new
Scanner(System.in);
int alphabet = 90;
System.out.print("Enter no: ");
int a = sc.nextInt();
for(int i =1; i<=a; i++) {
for(int j =1; j<=i; j++){
System.out.print((char) (alphabet - j-(25-a)) + " ");
}
System.out.println();
}
}
}
Write a program to print the given Number pattern.
Input Format:
Input consists of a single
integer.
Output
Format:
Refer sample outputs. There is a
trailing space at the end of each line.
Sample
Input 1:
5
Sample Output 1:
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
Sample
Input 2:
3
Sample Output 2:
1 2 3
1 2
1
package Mr_Programmer;
import
java.util.Scanner;
public class Main{
public static void
main(String[] args) {
Scanner sc=new
Scanner(System.in);
System.out.println("Enter
the value of n");
int n = sc.nextInt();
int m=1;
for(int i=n;i>=1;i--)
{
for(int j=1;j<=i;j++)
{
System.out.print(j+"
");
}
System.out.println();
}
}
}
Write a program to print the
Number pattern.
Input and Output Format:
Input consists of a single
integer that corresponds to the number of rows,n.
The output is the alphabet
pattern for the given input,n.
Sample Input 1:
5
Sample Output 1:
A
AB
ABC
ABCD
ABCDE
Sample Input 2:
7
Sample Output 2:
A
AB
ABC
ABCD
ABCDE
ABCDEF
ABCDEFG
package Mr_Programmer;
import java.util.Scanner;
public class Main{
public static void
main(String[] args) {
int alphabet = 65,m=0;
Scanner sc =new
Scanner(System.in);
int n = sc.nextInt();
for (int i = 0; i <= n; i++)
{
for (int j = 0; j <i; j++)
{
System.out.print((char) (alphabet + j) + "
");
m++;
}
System.out.println();
}
}
}