Skip to content

Performance Test (Beginner Level)

Henry Hare edited this page Jun 7, 2023 · 9 revisions

Ini the beninging

Error Catching Task

The code below is designed to print "integer equals 5". However, when you run it, it returns an error. Adjust the code so it will run

Python Version

_integer = 5_

_if integer = 5:_
    
  _print("integer equals 5")_

Java version

public class JavaTest {
    public static void main(String[] args) {
      Integer integer = 5;

      if (integer = 5) {
        System.out.println("integer equals 5");
      }
    }
}

Optimizing task

The code below functions, however, it can be optimized further. Adjust the code so it runs faster and clearer

Python Version

_testValue = 11_
_result = testValue % 3_

_if result == 0:_
    _print("Result = 0")_
_if result == 1:_
    _print("Result = 1")_
_if result == 2:_
    _print("Result = 2")_

Java Version

public class JavaTest {
    public static void main(String[] args) {
      Integer testValue = 11;
      Integer result = testValue % 3;

      if (result == 0) {
        System.out.println("result = 0");
      }
      if (result == 1) {
        System.out.println("result = 1");
      }
      if (result == 2) {
        System.out.println("result = 2");
      }
    }
}

Creation Task

Create a program that uses a boolean, a double/float, a modulus operator (%), and an if statement. Make sure to include comments in your program. For extra credit, use user input in your program too.

Clone this wiki locally