Answer to Question #242966 in Java | JSP | JSF for Nguu

Question #242966

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


1
Expert's answer
2021-09-27T07:18:20-0400
package com.company;
import java.util.*;

public class Main {

    public static void main(String[] args) {
   // prompt the user to enter a number
        Scanner input = new Scanner(System.in);
        System.out.print("Enter a whole  number: ");
        int number = input.nextInt();
        //Check the number is a positive or negative number
        if(number > 0)
        {
            int newnumber = number - 4;
            int answer = newnumber * 3;
            System.out.println("The number "+number+" is above zero");
            System.out.println("Result of the calculations = "+answer);
        }
        else if(number < 0)
        {
                int newnumber = number + 3;
                int answer = newnumber * 4;
                System.out.println("The number "+number+" is above zero");
                System.out.println("Result of the calculations = "+answer);
        }
        else{
            System.out.println("Try again the number entered is zero, it is neither negative nor positive");
        }

    }
}

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