Java Assignments Green = Easy, Blue = Normal, Red = Hard 01 02 03 04 05 06 07 08 09 By title |

The output of this code is nothing. The method writeSum should write the sum of three integers, namely i, i2 and i3 to the standard output.

### Java assignment 6: Find the sum of integers

Level: Easy

import java.util.Scanner; public class Math { void writeSum(int i, int i2, int i3) { // add the body of the method here! } public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter the first nr: "); int i = input.nextInt(); System.out.print("Enter the second nr: "); int i2 = input.nextInt(); System.out.print("Enter the third nr: "); int i3 = input.nextInt(); Math math = new Math(); math.writeSum(i, i2, i3); input.close(); } } /* In the following example the user enters 33, 21 and 12 Enter the first nr: 33 Enter the second nr: 21 Enter the third nr: 12 The sum is: 66 */

###### Author: Sar Maroof

### Answer explanation

The body of the method is written in the following code.

The following program allows the users to enter three integers respectively and it calculates the sum of them.

import java.util.Scanner; public class Math { void writeSum(int i, int i2, int i3) { int sum = i + i2 + i3; System.out.println("The sum is: " + sum); } public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter the first nr: "); int i = input.nextInt(); System.out.print("Enter the second nr: "); int i2 = input.nextInt(); System.out.print("Enter the third nr: "); int i3 = input.nextInt(); Math math = new Math(); math.writeSum(i, i2, i3); input.close(); } }

If you found this difficult, you might consider reading my book Java quizmaster for beginners. It is easy to understand, organized to learn Java in 17 days and it guides you to master Java code by solving 105 quizzes and 117 assignments. This book explains each chapter properly before starting with exercises and assignments. It is available on Amazon. See inside the book here!

Please, leave your questions, feedback and suggestions in the comments below!

SarMaroof.com offers a practical method to learn and improve your Java skills. It avoids unnecessary long boring theoretical explanations, but it uses many exercises and quizzes.

## Suggested Articles

## Books by Sar Maroof |

Subscribe to Sar Maroof's RSS feeds! Mail this page to a friend! Bookmark this page! |