Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Fresher-Trainee
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


nisha
Fresher-Trainee
1 Answer(s)      3 years and 9 months ago
Posted in : Java Beginners


the below pgm has an exception during run time, and has no errors during compilation , pls help. wat to do?

class Pyramid

{

public static void main(String[] args)

{

int x = 9;

for (int i = 1; i <= x; i++)

{  

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

 System.out.print("   "); 


  for (int k = i; k >= 1; k--)   

  System.out.print((k >=10) ?+ k : "  " + k);  

   for (int k = 2; k <=i; k++)     

   System.out.print((k>= 10) ?+ k : "  " + k); 

  System.out.println();  

}

}

}


Advertisement
View Answers

March 24, 2011 at 5:20 PM


i have run this code successfully...

public class Pyramid {
    public static void main(String[] args)

    {

        int x = 9;

        for (int i = 1; i <= x; i++)

        {

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

                System.out.print("   ");

            for (int k = i; k >= 1; k--)

                System.out.print((k >= 10) ? +k : "  " + k);

            for (int k = 2; k <= i; k++)

                System.out.print((k >= 10) ? +k : "  " + k);

            System.out.println();

        }

    }

}

i m coping its output as it is :

             1
                       2  1  2
                    3  2  1  2  3
                 4  3  2  1  2  3  4
              5  4  3  2  1  2  3  4  5
           6  5  4  3  2  1  2  3  4  5  6
        7  6  5  4  3  2  1  2  3  4  5  6  7
     8  7  6  5  4  3  2  1  2  3  4  5  6  7  8
  9  8  7  6  5  4  3  2  1  2  3  4  5  6  7  8  9


Related Tutorials/Questions & Answers:
Fresher-Trainee
Fresher-Trainee  a java program to calculate the area of different shapes using Multilevel Inheritance
Fresher-Trainee
Fresher-Trainee  the below pgm has an exception during run time, and has no errors during compilation , pls help. wat to do? class Pyramid { public static void main(String[] args) { int x = 9; for (int i
Advertisements
DATA Warehousing
DATA Warehousing       Position Vacant: DATA Warehousing (FRESHER/TRAINEE) Job Description...: DATA Warehousing (FRESHER/TRAINEE
 

 

 

DMCA.com