Given any whole number from user input, check whether it’s a positive or negative number. If the number is negative then increment it by 3 and multiply the result by 4, however if it’s a positive number then decrement by 4 and multiply it by 3. a) Create a flowchart to be followed to solve the above task b) Create a java program using your flowchart and see samples below
Sample run 1: Enter a whole number: 4
Output: The Number 4 is above zero hence,
Result of the calculations = 0
Sample run 2: Enter a whole number: -5
Output: The Number -5 is below zero hence,
Result of the calculations = -8
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a whole number: ");
int n = input.nextInt();
int resultCalculations = 0;
String message = "";
if (n > 0) {
resultCalculations = (n - 4) * 3;
message = ("The number " + n + " is above zero hence,");
} else if (n < 0) {
resultCalculations = (n + 3) * 4;
message = ("The number " + n + " is below zero hence,");
}
System.out.println(message);
System.out.println("Result of the calculations = " + resultCalculations);
input.close();
}
}
Comments
Leave a comment