Tell me the programme for this


@
1 2
@ @ @
1 2 3 4

Answers were Sorted based on User's Feedback



Tell me the programme for this @ 1 2 @ @ @ 1 2 3 4..

Answer / thati.donthi

public class PrintTriangle {

public static void main(String[] args) {
int n=4;
for(int i=1;i<=n;i++) {
for(int j=0;j<2*n-i;j++) {
System.out.print(" ");
}
for(int j=1;j<=i;j++) {
if(i%2 != 0) {
System.out.print("@"+" ");
} else {
System.out.print(j+" ");
}
}
System.out.println();
}
}
}

Is This Answer Correct ?    7 Yes 0 No

Tell me the programme for this @ 1 2 @ @ @ 1 2 3 4..

Answer / varun

public class HelloWorld{

public static void main(String []args){
int k=1;
for(int i=0;i<4;i++)
{
for(int j=0;j<=i;j++)
{
if(i%2==0)
System.out.print("@");
else
System.out.print(++k);
}
System.out.println();
k=0;
}
}
}

Is This Answer Correct ?    2 Yes 0 No

Tell me the programme for this @ 1 2 @ @ @ 1 2 3 4..

Answer / thati.donthi

public class PrintTriangle {

public static void main(String[] args) {
int n=4;
for(int i=1;i<=n;i++) {
for(int j=0;j<2*n-i;j++) {
System.out.print(" ");
}
for(int j=1;j<=i;j++) {
if(i%2 != 0) {
System.out.print("@"+" ");
} else {
System.out.print(j+" ");
}
}
System.out.println();
}
}
}

Is This Answer Correct ?    1 Yes 0 No

Tell me the programme for this @ 1 2 @ @ @ 1 2 3 4..

Answer / chantiraji

public class TriangleDisplay {

public static void main(String[] args) {
int n = 4;
for (int i = 1; i <= n; i++) {
for (int j = 4; j < 2 * n - i; j++) {
System.out.print(" ");
}
for (int j = 1; j <= i; j++) {
if (i % 2 != 0) {
System.out.print("@" + " ");
} else {
System.out.print(j + " ");
}
}
System.out.println();
}
}
}

Is This Answer Correct ?    0 Yes 0 No

Tell me the programme for this @ 1 2 @ @ @ 1 2 3 4..

Answer / sachin

package abc;

public class Sachin {

int n=4;
public static void main(String... args){
Sachin s=new Sachin();
for (int i=0;i<s.n;i++){
if(i%2==0){
for(int a=0; a<i+1;a++){
System.out.print("@");
}
}else{
for(int a=0; a<i+1;a++){
System.out.print(a+1);
}
}
System.out.println();
}
}
}

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Core Java Interview Questions

What is java util concurrentmodificationexception?

0 Answers  


1.what is the exact difference between applet and frame? 2.Do we use main method in frames?

5 Answers  


How does list work in java?

0 Answers  


What is the default value of local and global variables?

0 Answers  


What is an infinite loop? How infinite loop is declared?

0 Answers  






How do you make a thread in java?

0 Answers  


Why do we need autoboxing in java?

0 Answers  


printstream class method println() is calling using System class and its static object out .how it is explain any one in detail with example ?

1 Answers   TCS,


Why we override equals() method?

0 Answers  


What is an eror in java?

0 Answers  


how many design pattern r there? and wht design pattern u use and why ?

5 Answers   HP,


Can a final variable be manipulated in java?

0 Answers  


Categories