Code Monkey home page Code Monkey logo

stage0-module4-conditions-task5's Introduction

Tasks:

1. Basic switch.

Update the program so that it prints "default", using switch statement:

 public class BasicSwitch {
    public static void main(String[] args) {
        int a = 20;
        switch (a) {
            default:
                System.out.println("default");
                break;
            case 7:
                System.out.println("seven");
                break;
            case 10:
                System.out.println("ten");
                break;
            case 20:
                System.out.println("twenty");
                break;
        }
    }
}

2. Basic switch breaks.

Update the program so that it prints "twenty", using switch statement:

 public class BasicSwitch {
    public static void main(String[] args) {
        int a = 20;
        switch (a) {
            default:
                System.out.println("default");
            case 7:
                System.out.println("seven");
            case 10:
                System.out.println("ten");
            case 20:
                System.out.println("twenty");
        }
    }
}

3. Switch days in month printer.

Rewrite 7. Days in month printer. from task 3 with switch :

 public class SwitchDaysInMonthPrinter {
    public void amountOfDays(int month) {
    }
 }

4. Range numbers printer.

Create that will be printing if number is between 1 and 5("number is between 1 and 5"), 6 and 10("number is between 6 and 10") or "out of range" using switch statement. Number to be defined will be passed to method arguments:

    public class RangeNumbersPrinter {
         public void printRange(int number) {
         }
    }

5. Leap year printer.

Create a program to check whether a year is a leap year or not("leap" if true otherwise "not leap"). Year will be passed as argument in method parameter:

    public class LeapYearPrinter {
         public void isLeapYear(int year) {
         }
    }

So what should happen if we do not set break to any of the statements? (self exploring section).

stage0-module4-conditions-task5's People

Contributors

andrekukshinov avatar art-orient avatar sukora-stas avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.