Question: How to modify this code to accept the values of the two integers from a user at the keyboard? import java.util.Scanner; public class NumbersDemo

How to modify this code to accept the values of the two integers from a user at the keyboard?

 

import java.util.Scanner;

public class NumbersDemo

{

public static void main (String args[])

{

Scanner readme = new Scanner(System.in);

int n1;

int n2;

n1 = readme.nextInt();

n2 = readme.nextInt();

displayTwiceTheNumber(n1, n2);

displayNumberPlusFive(n1, n2);

displayNumberSquared(n1, n2);

}

public static void displayTwiceTheNumber(int n1, int n2)

{

int times2;

int times22;

times2 = n1 * 2;

times22 = n2 * 2;

System.out.println("2 times 2 is " + times2 + " and 3 times 2 is " +

times22);

}

public static void displayNumberPlusFive(int n1, int n2)

{

int plusFive;

int plusFive2;

plusFive = n1 + 5;

plusFive2 = n2 + 5;

System.out.println("2 plus 5 is " + plusFive + " and 3 plus 5 is " +

plusFive2);

}

public static void displayNumberSquared(int n1, int n2)

{

int numberSquared;

int numberSquared2;

numberSquared = n1 * n1;

numberSquared2 = n2 * n2;

System.out.println("squared is " + numberSquared + " and 3 squared is " + numberSquared2);

}

}

Step by Step Solution

3.36 Rating (146 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To modify the given code to accept the values of the two integers from a user at the keyboard you ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!