Advertisement
thotfrnk

numbersdemo

Apr 28th, 2023
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.89 KB | None | 0 0
  1.  
  2. import java.util.Scanner; //importing scanner
  3. public class NumbersDemo { //program begins
  4.     public static void main(String[] args) { //main method begins
  5.  
  6.         Scanner input = new Scanner (System.in); //scanner declaration
  7.  
  8.         //variable declaration
  9.         int num1, num2;
  10.  
  11.         //input statements to prompt the user to enter the two numbers
  12.         System.out.println("Please enter the first number: ");
  13.         num1 = input.nextInt();
  14.  
  15.         System.out.println("Please enter the second number: ");
  16.         num2 = input.nextInt();
  17.  
  18.         //method calls
  19.  
  20.         twiceTheNumber(num1);
  21.         twiceTheNumber(num2);
  22.  
  23.         displayNumberPlusFive(num1);
  24.         displayNumberPlusFive(num2);
  25.  
  26.         displayNumberSquared(num1);
  27.         displayNumberSquared(num2);
  28.  
  29.     } //main method ends
  30.  
  31.     //method twiceTheNumber takes the variable integer and multiplies it by two
  32.     public static void twiceTheNumber (int integer) {
  33.         //to multiply integer by 2
  34.         integer = integer * 2;
  35.  
  36.         //output statement for the modified integer
  37.         System.out.println("Number times 2: " +integer);
  38.     } //method twiceTheNumber ends
  39.  
  40.    //method displayNumberPlusFive takes the variable integer and adds 5 to it
  41.     public static void displayNumberPlusFive (int integer) {
  42.         //to add 5 to integer
  43.         integer = integer + 5;
  44.  
  45.         //output statement for the modified integer
  46.         System.out.println("Number plus 5: " +integer);
  47.     } //method displayNumberPlusFive ends
  48.  
  49.     //method displayNumberSquared takes the variable integer and squares it
  50.     public static void displayNumberSquared (int integer) {
  51.         //to square the integer
  52.         integer = integer * integer;
  53.  
  54.         //output statement for the modified integer
  55.         System.out.println("Number squared: " +integer);
  56.     } //method displayNumberSquared ends
  57. } //program ends
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement