JAVA PROGRAM(ALPHABET PATTERN)
AAB
ABC
ABCD
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication23;
/**
*
* @author Prakash
*/
public class JavaApplication23 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
for(int i=1;i<5;i++)
{
int a=65; //ASCII value of A
for(int j=1;j<=i;j++)
{
System.out.print((char)a);
a++;
}
System.out.println();
}
}
}
2. A
ABA
ABCBA
ABCDCBA
ABCDEDCBA
ABCDEFEDCBA
/** To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication23;
/**
*
* @author Prakash
*/
//enum week{
// sun,mon,tue,wed,thurs,fri,sat
//};
import java.util.*; // import java util
public class JavaApplication23 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner scr=new Scanner(System.in); // create scanner obj
int n;
System.out.println("Enter the number of rows. ");
n=scr.nextInt(); // accept a number
char c;
for(int i=1;i<=n;++i) // FOR LOOP FOR NUMBER OF ROWS
{
c='A';
for(int j=i;j<n;++j) // FOR LOOP FOR PRINTING SPACES
{
System.out.print(" ");
}
for(int k=1;k<=i;++k) // FOR LOOP FOR PRINTING ALPHABETS IN DESCENDING ORDER
{
System.out.print(c);
++c;
}
c-=2;
for(int l=1;l<i;++l) // FOR LOOP FOR PRINTING ALPHABETS IN ASCENDING ORDER
{
System.out.print(c);
--c;
}
System.out.println(); // INTRODUCING NEW LINE
}
}
}
output
Enter the number of rows.
6
A
ABA
ABCBA
ABCDCBA
ABCDEDCBA
ABCDEFEDCBA
A
BAB
CBABC
DCBABCD
EDCBABCDE
FEDCBABCDEF
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication23;
/**
*
* @author Prakash
*/
//enum week{
// sun,mon,tue,wed,thurs,fri,sat
//};
import java.util.*; // import java util
public class JavaApplication23 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner scr=new Scanner(System.in);
int n;
System.out.println("Enter the number of rows. ");
n=scr.nextInt();
char ch='A';
char c;
for(int i=1;i<=n;++i) // FOR LOOP FOR NUMBER OF ROWS
{
c=ch;
for(int j=i;j<n;++j) // FOR LOOP FOR PRINTING SPACES
{
System.out.print(" ");
}
for(int k=1;k<=i;++k) // FOR LOOP FOR PRINTING ALPHABETS IN DESCENDING ORDER
{
System.out.print(c);
--c;
}
c+=2;
for(int l=1;l<i;++l) // FOR LOOP FOR PRINTING ALPHABETS IN ASCENDING ORDER
{
System.out.print(c);
++c;
}
System.out.println(); // INTRODUCING NEW LINE
++ch; // INCREMENTING VALUE OF CH FOR NEXT ITERATION
}
} // end of main method
} // end of main class
/* OUTPUT
}
}
run:
Enter the number of rows.
6
A
BAB
CBABC
DCBABCD
EDCBABCDE
FEDCBABCDEF
BUILD SUCCESSFUL (total time: 4 seconds)
awsome post
ReplyDeletethnk you
DeleteThanks for sharing this post.
ReplyDeleteAlphabet Pattern Programs in Java .
how to print like that
ReplyDeleteA B C D E
B C D E A
C D E A B
D E A B C
E A B C D
hey, here is code:
Deletepackage javaapplication121;
public class JavaApplication121 {
/**
* @gurmeet
*/
public static void main(String[] args) {
char alpha[]={'A','B','C','D','E'};
for(int i=0;i<5;i++)
{
for(char a=alpha[i];a<='E';a++)
{
System.out.print(a+" ");
}
if(i>0)
{
for(int j=0;j<i;j++)
System.out.print(alpha[j]+" ");
}
System.out.println();
}
}
}
How to print this..
ReplyDeleteABCDEFGFEDCBA
ABCDEF FEDCBA
ABCDE EDCBA
A A
How to print like this
ReplyDeleteGreat
reat
eat
at
t
how to write
ReplyDeletea
bc
cde
defg
efghi
fghijk by using user input.Please help me.
nice PROB since o/p depends on user input
Delete/*
Gurmeet Coder
in this USER INPUT is no. of lines to be printed.
if any problem, please reply
*/
import java.util.*;
public class JavaApplication13 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the no. of lines:");
int n,i,j,c=96;
n=sc.nextInt();
for(i=1;i<=n;i++)
{
if(i>26)
{
c=(i%26)+97;
}
else
{
c+=i;
}
for(j=1;j<=i;j++)
{
System.out.print((char)c);
if(c==122)
{
c=96;
}
++c;
}
System.out.println();
c=96;
}
}
}
how to print
ReplyDeleteaba
b
/*
DeleteGurmeet
*/
public class JavaApplication11 {
public static void main(String[] args) {
int k=3,j,i,h=1;char c1='a',c2='b';
for(i=1;i<=2;i++)
{
for(j=h;j<=k;j++)
{
if(j%2!=0)
{
System.out.print(c1);
}
else
{
System.out.print(c2);
}
}
System.out.println(); k=2;h=2;
}
}
}
how to write codding of
ReplyDeleteabcba
bcb
b
how can i print
ReplyDeleteA
aa
BBB
bbbb
CCCCC
cccccc
/*
DeleteGurmeet Coder
*/
public class JavaApplication11 {
public static void main(String[] args) {
int i,j,k,capital=65,small=97;
for(i=1;i<=6;i++)
{
if(i%2!=0)
{
for(k=1;k<=i;k++)
{
System.out.print((char)capital);
}
++capital;
}
else
{
for(k=1;k<=i;k++)
{
System.out.print((char)small);
}
++small;
}
System.out.println();
}
}
}
How to. Print. The code
ReplyDeleteA
BC
DEA
BCDE
ABCDE
/*
DeleteGurmeet Coder
*/
public class JavaApplication11 {
public static void main(String[] args) {
char alphabet[]={'A','B','C','D','E'};
int i,j,k=0;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
System.out.print(alphabet[k]);++k;
if(k==5)
{
k=0;
}
}
System.out.println();
}
}
}
abcba
ReplyDeletebcb
c pattern program with dynamic input enter 1 only a, enter 2 ABA B and 3 abcba bcb c
Please give me the solution
Sorry for late reply please send me mail id
Delete