Create a Java program that implements a function called Double to calculate and return the double of an integer. It should prompt the user to enter the number beforehand.
Double
main
4
The double of 4 is 8
import java.util.Scanner; public class CalculateDouble { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); // Prompt the user to enter an integer System.out.println("Enter an integer:"); int number = scanner.nextInt(); // Call the Double function and display the result int result = doubleNumber(number); System.out.println("The double of " + number + " is " + result); scanner.close(); } // Function that calculates the double of an integer static int doubleNumber(int number) { return number * 2; } }
Click here to view the exercise solution
Share it on your social media and challenge your friends to solve programming problems. Together, we can learn and grow.
The code has been successfully copied to the clipboard.
Continue improving your Java programming skills with our selection of practical exercises from the lesson. Click on Practice and challenge your knowledge!
Develop your Java skills by creating a program with greeting and farewell functions. Learn to execute methods effectively from the main function (Main).
Create a Java program that implements two methods for greeting and saying goodbye. The greeting method should have a text parameter.
Create a Java program that implements a function called 'isAlphabetic()' which takes a text parameter from the user and checks if the text contains alphabetic characters from 'a' to 'z', including both uppercase and lowercase.
Explore text manipulation in Java with this intermediate-level exercise. Implement the changeLetter() function to modify a character in a text. Learn practically and enhance your mastery in programming!
Create a Java program that implements a function called "sum" that returns the sum of two integer numbers passed as parameters.
Create a Java program that implements a function called IsNumber that receives a text parameter from the user and check if the text is a number or not.
Create a Java program that serves as a calculator with the ability to add, subtract, multiply, or divide.
Create a program in Java that implements a function called CountSpaces that receives as a parameter a text requested from the user.
Create a Java program that asks the user for a number and save it in a text string.
Create a new version of the program Main parameter calculator where you can return the following error codes from Main.
Create a Java program that implements a function called FindMinMax that receives three parameters, an array of real numbers and two real numbers.
Create a program in Java that implements a function called WriteCenteredUnderline that receives as a parameter a text requested from the user.
Create a Java program that asks the user for 5 integers to store them in an array of integers.
Create a Java program that implements a function called InvertString receive receive a text by parameter and display them in reverse order.
Create a Java program that implements a function called Double to calculate and return double an integer.
Create a Java program that implements a function to check if a string is a palindrome or not.
Create a program in Java that implements a function called SearchGreatestValue that receives as an parameter an array of 5 real numbers requested from the user.
Create a Java program that implements a function called Power and calculate the result of raising an integer to another number.
Create a Java program that implements a function called WriteTitle that writes a text centered on the screen, in capital letters, with additional spaces and with one line above and another below.
Practice with exercises in Java that use functions of different types. Methods, functions with parameters or values by reference among others.
Free programming course with practical exercises and solutions in C#. Start learning right now!
Take your Exercises C# lessons everywhere with our Android app. Download it now from Google Play
Own and third party cookies to improve our services. If you go on surfing, we will consider you accepting its use.