Saturday, 14 April 2012

Java Question and Answer

Write a program to display Following Output:


Q1
1
1 2
1 2 3
1 2 3 4

Q2
1
2 3
4 5 6
7 8 9 10


Q3
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1


Q4
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
5 5 5 5 5


Q5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5


Q6
            1
         1 2 1
      1 2 3 2 1
   1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1

Q7
            1
         1 2 1
      1 2 3 2 1
   1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
   1 2 3 4 3 2 1
      1 2 3 2 1
         1 2 1
            1
Q8
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1


Write Programs for the following Question below:
A single answer too will be appreciated.


Related post:
10 basic solved java qustions 

9 comments:

  1. Comment the answers here..!!!

    ReplyDelete
  2. Q4: public class java {

    public static void main (String args[])
    {
    for(int i=1; i<=5; i++)
    {
    for(int j=1; j<=5; j++)

    {
    System.out.print(i);
    }
    System.out.println("");
    }
    }
    }

    ReplyDelete
  3. Q1: public class java {

    public static void main (String args[])
    {
    for(int i=1; i<=5; i++)
    {
    for(int j=1; j<=i; j++)

    {
    System.out.print(j);
    }
    System.out.println("");
    }
    }
    }

    ReplyDelete
  4. Nice job buddy...other programmers too are Welcomed..!!

    ReplyDelete
  5. Q2:
    int k = 1;
    for(int x = 1; x <= 4; x++){
    for(int y = 1; y <= x; y++){
    System.out.print(k);
    k++;
    }
    System.out.println("");
    }

    ReplyDelete
  6. Q5:
    for(int x = 1; x <= 5; x++){
    for(int y = 1; y <= 5; y++){ System.out.print(y);
    }
    System.out.println("");
    }

    ReplyDelete
  7. Q6


    public static void main( String arg[] )
    {
    int tamano = 5;

    for( int i = 1 ; i <= tamano ; i++ )
    {
    for( int x = i ; x <= tamano ; x++ )
    {
    System.out.print(" ");
    }

    for( int j = 1 ; j <= i ; j++ )
    {

    System.out.print("" + j);
    }

    for( int w = i-1 ; w >= 1 ; w-- )
    {
    System.out.print("" + w);
    }

    System.out.println();
    }
    }

    ReplyDelete
  8. Q7

    public static void main( String arg[] )
    {
    int tamano = 5;

    for( int i = 1 ; i <= tamano ; i++ )
    {
    for( int x = i ; x <= tamano ; x++ )
    {
    System.out.print(" ");
    }

    for( int j = 1 ; j <= i ; j++ )
    {

    System.out.print("" + j);
    }

    for( int w = i-1 ; w >= 1 ; w-- )
    {
    System.out.print("" + w);
    }

    System.out.println();
    }

    for( int i = 1 ; i <= tamano ; i++ )
    {
    System.out.print(" ");
    for( int x = 1 ; x <= i ; x++ )
    {
    System.out.print(" ");
    }

    for( int j = 1 ; j <= tamano-i ; j++ )
    {

    System.out.print("" + j);
    }

    for( int w = tamano-i-1 ; w >= 1 ; w-- )
    {
    System.out.print("" + w);
    }

    System.out.println();
    }
    }

    ReplyDelete
  9. Q8


    public static void main( String arg[] )
    {
    int tamano = 5;

    for( int i = 1 ; i <= tamano ; i++ )
    {
    for( int x = i ; x <= tamano ; x++ )
    {
    System.out.print("");
    }

    for( int j = 1 ; j <= i ; j++ )
    {

    System.out.print("" + j);
    }

    for( int w = i-1 ; w >= 1 ; w-- )
    {
    System.out.print("" + w);
    }

    System.out.println();
    }

    for( int i = 1 ; i <= tamano ; i++ )
    {
    System.out.print("");
    for( int x = 1 ; x <= i ; x++ )
    {
    System.out.print("");
    }

    for( int j = 1 ; j <= tamano-i ; j++ )
    {

    System.out.print("" + j);
    }

    for( int w = tamano-i-1 ; w >= 1 ; w-- )
    {
    System.out.print("" + w);
    }

    System.out.println();
    }
    }

    ReplyDelete