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
Step: 1
To modify the given code to accept the values of the two integers from a user at the keyboard you ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started