1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
/* Java Pyramid 6 Example This Java Pyramid example shows how to generate pyramid or triangle like given below using for loop. ***** **** *** ** * * ** *** **** ***** */ public class JavaPyramid6 { public static void main(String[] args) { //generate upper half of the pyramid for(int i=5; i>0 ;i--){ for(int j=0; j < i; j++){ System.out.print("*"); } //create a new line System.out.println(""); } //generate bottom half of the pyramid for(int i=1; i<= 5 ;i++){ for(int j=0; j < i; j++){ System.out.print("*"); } //create a new line System.out.println(""); } } } /* Output of the example would be ***** **** *** ** * * ** *** **** ***** */ |
Its a Great Site for java lovers Specially Beginners
public class patern1
{
public static void main(String[] args)
{
int k=1;
for(int i=5; i>0 ;i–)
{
for(int j=i; j >0; j–)
{
System.out.print(k++);
}
k=k-i;
k++;
System.out.println(“”);
}
}
}
/*
Output of the patern1 would be
12345
2345
345
45
5*/
for(int i=1;i<=5;i++){
for(int j=i;j<=5;j++){
System.out.print(j);
}
System.out.println(” “);
}
how about this code?
12345
2345
345
45
5
thanks 😀
public static void main(String[] args) {
for( int i=1; i<6; i++){
for( int j=i; j<6; j++){
System.out.print(j);
}
System.out.print(” \n”);
}
}
how about this code?
54321
4321
321
21
1
public class patern
{
public static void main(String[] args)
{
for(int i=5; i>0 ;i–)
{
for(int j=i; j >0; j–)
{
System.out.print(j);
}
System.out.println(“”);
}
}
/*Output of the patern would be
54321
4321
321
21
1*/
Can someone give me a code for this
111111
22222
3333
444
55
6
thnks in advnce
int i,j;
for(i=1;i<=6;i++){
for(j=6;j>=i;j–){
System.out.print(i);
}
System.out.print(“\n”);
}
anyone can answer this code?
o o
oo oo
ooo ooo
oooooooo
thank you : >
int i,j,k;
for(i=1;i<5;i++)
{System.out.println();
for(j=i;j>=1;j–)
{
System.out.print(“o”);
}
System.out.print(” “);
for(k=i;k>=1;k–)
{
System.out.print(“o”);
}
}
anyone can answer this code?
o
oo
ooo
oooo
thanks.. : >
for(int i=1;i<5;i++)
{
for(int j=0;j<i;j++){ system.out.print(“o”);=”” }=”” system.out.println(“”);=”” }=””>
anyone can solve this code?
____o
___oo
__ooo
_oooo
ooooo
thanks alot : >
public static void main(String[] args) {
for(int i=1;i<=5;i++) {
for(int j=1;j<=5-i;j++) {
System.out.print(“_”);
}
for(int k=1;k<=i;k++) {
System.out.print(“o”);
}
System.out.println();
}
}
Show me code for this out put please
enter name: java
Output:
j
a j
v a j
a v a j
if input is 12?
it should display 4 numbers in a line starting from 1
ex 1 2 3 4
5 6 7 8
9 10 11 12
???
00
00
00
00
how to print..
class P1
{
public static void main(String[] args)
{
int y = 0;
for(int i=1; i<= 4 ;i++)
{
for(int j=1; j<=2 ; j++)
{
System.out.print(y);
}
System.out.println(“”);
}
}
}
Hi,please help me on below example pattern
12345
23451
34512
45123
54321
your pattern should be
12345
23451
34512
45123
51234
then code be this :
for (int i=1; i<=5;i++)
{
for(int j=i;j<=5; j++)
{
System.out.print(j+” “);
}
for(int j=1; j<i;j++) {=”” system.out.print(j+”=”” “);=”” }=”” system.out.println();=”” }=””>
*
***
*****
*******
*********
please give me a code.
how about this ??
9 8 7 6 5 4 3 2 1 0
8 7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
6 5 4 3 2 1 0
5 4 3 2 1 0
5 3 2 1 0
3 2 1 0
2 1 0
1 0
0
thnks
public static void main(String[] args) {
int i,j;
for(i=9;i>=0;i–)
{ System.out.println();
for(j=i;j>=0;j–)
{
System.out.print(j);
}
}
}
how about this
1
23
456
78910
and so on
int c=0;
for (int i=1; i<=5;i++)
{
for(int j=1;j<=i; j++)
{
System.out.print(++c
+” “);
}
System.out.println();
}
how about this code
*****
****
***
**
*
Can anyone have solution for this?
–*–
-***-
*****
-***-
–*–
Other than this:
class PyramidStar{
public static void main(String []args){
System.out.println(” * “);
System.out.println(” *** “);
System.out.println(“*****”);
System.out.println(” *** “);
System.out.println(” * “);
}
}
public static void main(String[] args) {
int i,j,k,l;
for(i=1;i<=5;i+=2)
{ System.out.println();
for(j=i;j<5;j+=2)
{
System.out.print(“_”);
}
for(k=i;k>=1;k–)
{
System.out.print(“*”);
}
for(l=i;l<5;l+=2)
{
System.out.print(“_”);
}
}
for(i=3;i>=1;i-=2)
{ System.out.println();
for(j=i;j<=3;j+=2)
{
System.out.print(“_”);
}
for(k=i;k>=1;k–)
{
System.out.print(“*”);
}
for(l=i;l<=3;l+=2)
{
System.out.print(“_”);
}
}
System.out.println();
}
int k = 0;
for(int i = 1; i <= 3; ++i) {//rows=3=i
for(int j = 1; j <= 3 – i; ++j) {
System.out.print(“_”);
}
while(k != 2 * i – 1) {
System.out.print(“*”);
++k;
}
for(int j = 1; j <= 3 – i; ++j) {
System.out.print(“_”);
}
k=0;
System.out.println();
}
for(int i = 2; i >= 1; –i) { //rows=2=i
for(int j = 1; j <= 3 – i; ++j) {
System.out.print(“_”);
}
while(k != 2 * i – 1) {
System.out.print(“*”);
++k;
}
for(int j = 1; j <= 3 – i; ++j) {
System.out.print(“_”);
}
k=0;
System.out.println();
}
}
How about this code Please ??? its view should look like a normal triangle??? .
1
1 2 1
1 2 4 2 1
1 2 4 8 4 2 1
1 2 4 8 16 8 4 2 1
1 2 4 8 16 32 16 8 4 2 1
what is the code for
12345
234
3
public class Ques {
public static void main(String[] args) {
int a,b;
for(a=1;a<=3;a++)
{System.out.println();
for(b=a;b<7-a;b++)
{
System.out.print(b);
}
}
}
}
can anybody give me code for this its very urgent tomarrow is my exam
1
23
456
78910
Can someone give me code for this. .
1
2 5
3 6 8
4 7 9 10
how about this code ..? And I need to take this numbers from a arraylist..
can anybody provide this code ..urgent
1 2 3 4 5 6 7 8 9 10
11 12 13 14 15
16 17 18
19 20
21
hey ,
how about that code ???
*******
-*****-
–***–
—*—
–***–
-*****-
*******
int x,y,z,w;
for(x=1;x<8;x+=2)
{System.out.println();
for(y=x;y>1;y-=2)
{
System.out.print(“_”);
}
for(z=x;z<8;z++)
{
System.out.print(“*”);
}
for(w=x;w>1;w-=2)
{
System.out.print(“_”);
}
}
for(x=1;x<6;x+=2)
{
System.out.println();
for(y=x;y<5;y+=2)
{
System.out.print(“_”);
}
for(z=1;z<=x+2;z++)
{
System.out.print(“*”);
}
for(w=x;w<5;w+=2)
{
System.out.print(“_”);
}
}
0
1 0
0 1 0
1 0 1 0
0 1 0 1 0
i dont understand my mistake regarding this how do i get that i mean whats the mistake in my code
public static void main(String abc[]) {
int i,j,l=5;
for(i=1;i<=5;i++) {
for(j=i;j>=1;j–)
System.out.print(j%2);
System.out.println();
}
}
public class Pyramid1 {
public static void main(String[] args) {
for(int i=1;i<=5;i++){
for(int j=1;j<=i;j++){
if((j-i)%2==0){
System.out.print(‘0’);
}else{
System.out.print(‘1’);
}
}
System.out.println(” “);
}
}
}
5
4 5
3 4 5
2 3 4 5
1 2 3 4 5
plz help me with it..down one.
1
2 2 2
3 3 3 3 3
4 4 4 4 4 4 4
5 5 5 5 5 5 5 5 5
6 6 6 6 6 6 6 6 6 6 6
Can someone help me to get this output? how about the code in java program?
———–1
——–2 2 2
——3 3 3 3 3
—-4 4 4 4 4 4 4
—5 5 5 5 5 5 5 5 5
6 6 6 6 6 6 6 6 6 6 6
Can someone help me to get this output? how about the code in java program?
int C=1;
int m=1;
for(int i = 1; i <= 6; ++i) {
for(int j = 1; j <= 6 – i; ++j) {
System.out.print(“_”);
}
for(int j=1; j<=m; j++){
System.out.print(C);
}
m+=2;
C++;
System.out.println();
}
can someone give me a code for this
1
123
12345
123
1
How to print?
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
Plz tell me fast