1 of 12

Coding Club

Eagle Ridge Middle School

Akash Pamal

Session 4 - Nov 2nd

2 of 12

Today’s Talk

  • Control Statement - If and if/else
  • Practice Problems

3 of 12

Positive / Negative Check

  • Complete last week’s program that prints positive or negative number
  • Check for zero (0) as the input
  • Program is available here (link on Coding Club website)
    • https://docs.google.com/document/d/1eplVEQGwNXeh4Z58BAN_ieSSunuRqBiizLSFbGO_CS8/edit?usp=sharing

4 of 12

Control Statement - if

if (boolean expression) {System.out.println("This line is printed if the boolean expression is true");}

5 of 12

Control Statement - if

int a = 10;

if (a > 0) {System.out.println("This line is printed if the boolean expression is true");}

6 of 12

Control Statement - if / else

if (boolean expression) {System.out.println("This line is printed if the boolean expression is true");} else {

System.out.println("This line is printed if the boolean expression is false");

}

7 of 12

Control Statement - if / else

int a = 20;

if (a < 0) {System.out.println("This line is printed if the boolean expression is true");} else {

System.out.println("This line is printed if the boolean expression is false");

}

8 of 12

Reading Input

import java.util.scanner;

Scanner sc = new Scanner();

int i = sc.nextInt();

9 of 12

Program

  • Write a program to take an input from user and print if the number is positive or negative number

import java.util.scanner;

Scanner sc = new Scanner(System.in);

int i = sc.nextInt();

10 of 12

Program

import java.util.scanner;

Public class positiveCheck{

public static void main (String [] args){

Scanner sc = new Scanner(System.in);

int i = sc.nextInt();

System.out.println(i);

}

}

11 of 12

Advanced Problems

  • Given 2 int values, return whichever value is nearest to the value 10, or return 0 in the event of a tie. Note that Math.abs(n) returns the absolute value of a number

public int close10(int a, int b) {

}

12 of 12

Thank You