Guide to Teaching Computer Science by Orit Hazzan Tami Lapidot & Noa Ragonis

Guide to Teaching Computer Science by Orit Hazzan Tami Lapidot & Noa Ragonis

Author:Orit Hazzan, Tami Lapidot & Noa Ragonis
Language: eng
Format: epub
Publisher: Springer London, London


import java.util.Scanner;

public class Condition {

public static Scanner input  =  new Scanner(System.in);

public static void main(String args) {

double num;

System.out.println (“enter number”);

num  =  input.nextDouble();

System.out.println (“good number”);

System.out.println (“end”);

}

}

Task 1, Part A

Open a new class and type the class presented on the left.

Save it, run it, check its output and write it down.

import java.util.Scanner;

public class Condition {

public static Scanner input  =  new Scanner(System.in);

public static void main(String args) {

double num;

System.out.println (“enter number”);

num  =  input.nextDouble();

if (num  >  0)

System.out.println (“good number”);

System.out.println (“end”);

}

}

Task 1, Part B

We now change the class so that the message “good number” is printed only if the variable num is positive.

Change the class according to the code on the left.

Save it and run it.

When the program waits for an input, type a positive number.

The output is: ________________________

Run it again. This time, when the program waits for an input, type a negative number.

The output is: ________________________



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.