Function double Learn programming Java

Lesson:

Functions


Exercise:

Function double


Objetive:

Create a function named "Double" to calculate and return an integer number doubled. For example. Double(7) should return 14.


Code:

import java.util.*;
public class Main
{
	public static int Double(int number)
	{
		return number * 2;
	}

	public static void main(String[] args)
	{
		System.out.print("Enter a number: ");
		int number = Integer.parseInt(new Scanner(System.in).nextLine());
		System.out.printf("Double of %1$s is %2$s" + "\r\n", number, Double(number));
	}
}

Juan A. Ripoll - Systems Tutorials and Programming Courses ©  All rights reserved.  Legal Conditions.