Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login

if statements

pinkberrygirl31
pinkberrygirl31 


Exercise 1 Create a Java class named IfDemo that has a “main” similar to class FirstProgram in Lab 1. 1. Write a program that will print whether a number is odd or even. A number is even you divide it by 2 and the remainder is 0. Use an if-else statement and the modulus (%) operator to create output like the following: Input a number: 35 The number 35 is odd. And, if the program is run again: Input a number: 76 The number 76 is even. Copy the source code and the output into a word processing document called Lab3. Exercise 2 A number is positive if it is greater than 0, negative if it is less than 0, and zero if it’s value is 0. Comment out the code from exercise 1 and add code to create output like the following: Input a number: 35 The number 35 is positive. And, if the program is run again: Input a number: -53 The number -53 is negative. And, if the program is run again: Input a number: 0 The number 0 is zero. Copy the source code and the output into the word processing document. Exercise 3 A number is a teen if its value is between 13 and 19 inclusively. Comment out the code from exercise 2 and add code to create output like the following: Input a number: 35 The number 35 is not a teen. And, if the program is run again: Input a number: 16 The number 16 is a teen. Copy the source code and the output into the word processing document and submit the file. Attachments
Tags
Clarifications

Answers

Java - Lab3 - Solution

dickersonka
dickersonka 



Attached is the solution including source and output for the Lab exercise. Attachments
Lab3.zip (14 K) Download

Preview
public static void main(String[] args){ Scanner input = new Scanner(System.in); System.out.print("Input a number: "); int number = input.nextInt(); if((number % 2) == 0){ System.out.println("The number " + number + " is even."); } else { System.out.println("The number " + number

Preview
args){ Scanner input = new Scanner(System.in); System.out.print("Input a number: "); int number = input.nextInt();

Preview
System.out.print("Input a number: "); int number = input.nextInt(); if(number > 0){ System.out.println("The number " + number + " is positive.");

Preview
System.out.println("The number " + number + " is a teen."); } else { System.out.println("The number " + number

Screenshots
Purchase Answer

IfDemo solutions

SW_wizard
SW_wizard 



I have completed the assignment. Attachments
IfStatementDemo.zip (1 K) Download
Preview
System.out.println("Input a number"); int num = scan.nextInt(); if ((num % 2) == 0) {

Preview
is positive"); } else if (num < 0) { System.out.println("The number "+num+" is negative"); } else {

Preview
scan = new Scanner(System.in); System.out.println("Input a number"); int num = scan.nextInt(); if ((num <= 19) && (num

Lab3.docx (15 K) Download
Screenshots
Purchase Answer

If Statement

mariobeka
mariobeka 



public class IfDemo {

public static void main (String[] args) throws NumberFormatException, IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
Attachments
Lab3.docx (93 K) Download
IfDemo.java (1 K) Download Preview
"+ number + " is negative"); } else if (number == 0){ System.out.println("The number "+ number + " is zero"); }*/ if(number > 13 && number < 19){ System.out.println("The number "+ number + " is a ten."); } else {

Screenshots
Purchase Answer