Friday, 1 April 2016

Chapter 1 Exercise 6, Introduction to Java Programming, Tenth Edition Y. Daniel LiangY.

(Summation of a series) Write a program that displays the result of

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


public class Exercise_06 {

    public static void main(String[] args) {
        int answer = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9;

        System.out.println("1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 = " + answer);
    }
}

No comments :

Post a Comment