Answer to Question #247693 in Java | JSP | JSF for Nelly

Question #247693

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.


1
Expert's answer
2021-10-06T16:09:00-0400
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner keyBoard = new Scanner(System.in);
		System.out.print("Enter a whole number: ");
		int number = keyBoard.nextInt();
		int result = 0;
		if (number > 0) {
			result = (number - 4) * 3;
			System.out.println("The number " + number + " is above zero hence");
		} else if (number < 0) {
			result = (number + 3) * 4;
			System.out.println("The number " + number + " is below zero hence");
		}
		System.out.println("Result of the calculations = " + result);
		keyBoard.close();
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS