Monday, 30 October 2017

Introduction to Java program




Problem:1.4
                                Write a program that displays the following table:
a         a^2               a^3
1           1                  1
2           4                  8
3          9                  27
4          16               64
 Description:
                              By taking integer type variable and assign this variable to 1 after one statement it value can be increased by 1. The statement can be written given below.
Solution:
             public class Message {

    public static void main(String[] args) {
         int a=1;
        System.out.println("a            a^2          a^3");
         System.out.println(a+"            "+(a*a)+"            "+(a*a*a));
          a++;
            System.out.println(a+"            "+(a*a)+"            "+(a*a*a));
            a++;
             System.out.println(a+"            "+(a*a)+"            "+(a*a*a));
             a++;
              System.out.println(a+"            "+(a*a)+"            "+(a*a*a));
    }
   
}

Output
                       


No comments:

Post a Comment