Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner; //importing scanner
- public class NumbersDemo { //program begins
- public static void main(String[] args) { //main method begins
- Scanner input = new Scanner (System.in); //scanner declaration
- //variable declaration
- int num1, num2;
- //input statements to prompt the user to enter the two numbers
- System.out.println("Please enter the first number: ");
- num1 = input.nextInt();
- System.out.println("Please enter the second number: ");
- num2 = input.nextInt();
- //method calls
- twiceTheNumber(num1);
- twiceTheNumber(num2);
- displayNumberPlusFive(num1);
- displayNumberPlusFive(num2);
- displayNumberSquared(num1);
- displayNumberSquared(num2);
- } //main method ends
- //method twiceTheNumber takes the variable integer and multiplies it by two
- public static void twiceTheNumber (int integer) {
- //to multiply integer by 2
- integer = integer * 2;
- //output statement for the modified integer
- System.out.println("Number times 2: " +integer);
- } //method twiceTheNumber ends
- //method displayNumberPlusFive takes the variable integer and adds 5 to it
- public static void displayNumberPlusFive (int integer) {
- //to add 5 to integer
- integer = integer + 5;
- //output statement for the modified integer
- System.out.println("Number plus 5: " +integer);
- } //method displayNumberPlusFive ends
- //method displayNumberSquared takes the variable integer and squares it
- public static void displayNumberSquared (int integer) {
- //to square the integer
- integer = integer * integer;
- //output statement for the modified integer
- System.out.println("Number squared: " +integer);
- } //method displayNumberSquared ends
- } //program ends
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement