Respuesta :
Answer:
import java.util.Scanner;
public class NumSquared {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
int userNum = 0;
int userNumSquared;
userNum = scnr.nextInt();
userNumSquared = userNum * userNum; // Bug here; fix it when instructed
System.out.println(userNumSquared); // Output formatting issue here; fix it when instructed
}
}
Explanation:
For case 1 you can in initialize the input with a number as have done.
For case 2, I changed the '+' to '*' so that I can get the square as required by the question
For case 3, I used a println(), because it will print the value of UserNumSquared and also print a new line.
The fix to the bugs in the program are:
- Change userNumSquared = userNum + userNum; to userNumSquared = userNum * userNum;
- Change System.out.print(userNumSquared); to System.out.println(userNumSquared);
The program is meant to
- Calculate the square of a number
- Print the calculated square and followed by a new line
The square of the input number is wrongly calculated on line 8 as:
userNumSquared = userNum + userNum;
The above operation will only return twice the input number. To fix the bug on this line, we simply change the addition operation (+) to multiplication (*).
So, the instruction on line 8 should be replaced with:
userNumSquared = userNum * userNum;
On line 9, where the squared number is printed;
The print instruction is meant to print the squared number, followed by a new line.
There are several ways to achieve this, but the simplest of these ways is by using println.
So, the instruction on line 9 should be replaced with:
System.out.println(userNumSquared);
Read more about java programs at:
https://brainly.com/question/2266606