1 answer

Question 4 (3 mark) : Write a Java program to ask the user to input an...

Question:

Question 4 (3 mark) : Write a Java program to ask the user to input an integer number from the keyboard. The output should in

Question 4 (3 mark) : Write a Java program to ask the user to input an integer number from the keyboard. The output should indicate whether it is positive, zero, or negative, an even number or an odd number. REQUIREMENTS • Your code should ask user to input an integer number, then decide its sign and parity based on this input. • Your code should use if-else statement. Your code must work exactly as the specification and the output should be exactly the sam as the output example. 5 example of the program output (the texts in bold indicate the user input): Example 1: Property Please input a number: 6 6 is a positive, even number. Example 2: Please input a number: -27 -27 is a negative, odd number. Example 3: Property Please input a number: 25 25 is a positive, odd number. Example 4: Property Please input a number: -16 -16 is a negative, even number. Example 5: Property Please input a number: 0 0 is a zero, even number.

Answers

Answer:

Here is the java code as per your requirement

Raw code:

//importing scanner class for input from user

import java.util.Scanner;

//class named Numbers

public class Numbers{

//main

public static void main(String[] args) {

//creating scanner object

Scanner sc = new Scanner(System.in);

//prompt to the user

System.out.print("Property Please input a number: ");

//getting input

int num =sc.nextInt();

//checking if the input is 0

if(num==0) {

System.out.println(num+" is a zero, even number.");

}

//if input is greater than 0 its positive

if(num>0) {

//checking if its odd or even

if(num%2==0) {

System.out.println(num + " is a positive, even number.");

}

else {

System.out.println(num + " is a positive, odd number.");

}

}

//if number is less than 0 its negative

if(num<0) {

//checking if its odd or even

if(num%2==0) {

System.out.println(num + " is a negative, even number.");

}

else {

System.out.println(num + " is a negative, odd number.");

}

}

}

}

Code in the editor:

9 18 DNumbers.java x 1 //importing scanner class for input from user 2 import java.util.Scanner; 3 // class named Numbers 4 p

output:

Console X <terminated> Numbers (Java Application] /Library/Java/JavaVirtual Mac Property Please input a number: 0 O is a zero

<terminated Numbers (Java Application] /Library/Java/JavaVirtual Mac Property Please input a number: -25 -25 is a negative, o

<terminated> Numbers [Java Application] /Library/Java/JavaVirtual Machines/jdk1.8.0_231.jdk/Con Property Please input a numbe

Console X <terminated Numbers [Java Application] /Library/Java/Javavirtual Property Please input a number: 7 7 is a positive,

Hope this helps you! If you still have any doubts or queries please feel free to comment in the comment section.

"Please refer to the screenshot of the code to understand the indentation of the code".

Thank you! Do upvote.

.

Similar Solved Questions

1 answer
O1-The angular position of a angular speed of the point at t = 3s (A)6 rad...
o1-The angular position of a angular speed of the point at t = 3s (A)6 rad s(B) 10 rads (C)14r point on a wheel is described by θ (t) = 2t + 2t3(rad). Find t ad s-t (D) 18 rad s1 (E) 22 reds A wheel starts from rest and rotates with const ant angular acceleration to reach an ingular spec...
1 answer
The following adjusted trial balance is the result of the adjustments made at the end of...
The following adjusted trial balance is the result of the adjustments made at the end of the month of March for Martin Corporation. Use these adjusted values to journaline the closing entries for Martin Corporation Cash 24,750 Accounts Receivable 5.750 Office Supplies 3.525 Store Supplies 4,785 Mach...
1 answer
Retailers and businesses offer frequency programs to consumers. These rewards often come with a "price". That...
Retailers and businesses offer frequency programs to consumers. These rewards often come with a "price". That price is sharing your personal information with these companies, like addresses, phone numbers, emails, demographics, etc. These companies can even track our purchases through bar co...
1 answer
8)Determine the value of a test statistic to test the null hypothesis that a population with...
8)Determine the value of a test statistic to test the null hypothesis that a population with the following number of individuals is in Hardy-Weinberg equilibrium: Number of TT individuals = 1324 Number of Tt individuals = 658 Number of tt individuals = 198 Question 8 options: 1) 0.433 ...
1 answer
2. (6 points) Consider the function y 11+Vx+ve (a) (2 points) Compute (b) (4 points) In...
2. (6 points) Consider the function y 11+Vx+ve (a) (2 points) Compute (b) (4 points) In several complete sentences, explain how you did this calculation. Your answer should clearly indicate which differentiation rules you have used, and the parts of those rules should be identified (eg. if you used ...
1 answer
Describe how the immune cells can distinguish from self and non-self
Describe how the immune cells can distinguish from self and non-self...
1 answer
1. A, on a coordinate axis (1)sketch x? + (y – 5)2 = 9, (2)describe the...
1. A, on a coordinate axis (1)sketch x? + (y – 5)2 = 9, (2)describe the graph, (3)the graph is revolved about the x-axis, set-up integral which will compute its VOLUME, simplify the integrand as much as possible but DO NOT DO THE INTEGRATION. B. The triangle whose vertices are (0,0), (2,8) and...
1 answer
A ray of light impinges from air onto a block of ice (n = 1.309) at...
A ray of light impinges from air onto a block of ice (n = 1.309) at a 69.0° angle of incidence. Assuming that this angle remains the same, find the difference 02, ice - 02, water in the angles of refraction when the ice turns to water (n = 1.333). 02, ice -2, water Additional Materials Section 2...
1 answer
QUESTION 3 ABC Corp announces that Revenues are being restated downward for the prior year and...
QUESTION 3 ABC Corp announces that Revenues are being restated downward for the prior year and that its auditor has resigned. What do you expect the impact to be on Credit Default Swap pricing? Increase b. Decrease No change d. None of the above...
1 answer
For the decomposition of A to B and C A(n) B(g) + C(g) how will the...
For the decomposition of A to B and C A(n) B(g) + C(g) how will the reaction respond to each of the following changes at equilibrium? Drag the appropriate items to their respective bins. double the concentration of B and haive the double the concentrations add more A double the container volume doub...
1 answer
Question 6: The history of data visualization includes contemporary methods that permit "linkages" of related data...
Question 6: The history of data visualization includes contemporary methods that permit "linkages" of related data sets. Which of the following exemplifies the linkages concept? Select one: a. A researcher explored a scatterplot of income and patriotism for three different groups of voters, ...
1 answer
What statistic describes the distance from an observed value to the mean in units of standard...
What statistic describes the distance from an observed value to the mean in units of standard deviation, when working with a large sample that is normally distributed? a: Critical value of T b: F score c: Chi-square dz...
1 answer
QUESTION 2 (5 Marks) Dunning Ltd. manufactures a popular power nail gun suitable for the home...
QUESTION 2 (5 Marks) Dunning Ltd. manufactures a popular power nail gun suitable for the home renovator. Financial and other data for this product for the last twelve months are as follows: Sales 20,000 units Selling price $130 per unit Variable manufacturing cost $50 per unit Fixed manufacturing co...
1 answer
A wholly-owned subsidiary's revalued net assets at the date of acquisition consist of indefinite life identifiable...
A wholly-owned subsidiary's revalued net assets at the date of acquisition consist of indefinite life identifiable intangible assets valued at $500,000 at the date of acquisition. Impairment of these intangibles as of the beginning of the current year is $50,000, and impairment testing for the c...
1 answer
Case study please solve
Mr. L, 70 years old si sent to hospital after visiting his physician with increasing painful muscle cramps after ambulating. He also hast rest pain and a non-healing ulcer of the big toe on the right foot. He lives alone and his medical history is significant for hypertension.Dx: Peripheral artery d...
1 answer
Continued on from case study 8. According to the Investor Presentation, what is one strategy that...
Continued on from case study 8. According to the Investor Presentation, what is one strategy that Michael Hill has planned for its cash flow? 1. Michael Hill International Limited (hereafter known as “Michael Hill”) ordinary shares are listed on the Australian Securities Exchange (ASX). ...