Giter Club home page Giter Club logo

kotlin-example's Introduction

Kotlin-Example

Practical 1.1.1 Aim:- Dog hears frequencies starting from 67 Hertz to 45000 Hertz (both inclusive). Pass value X Hertz, find whether dog can hear them or not. Print YES if value between 67 to 45000. Otherwise print NO

Code in Kotlin: fun main() { // create scanner object to take input from user val scanner = Scanner(System.in) // take input from user print("Enter the frequency value in Hertz: ") val frequency = scanner.nextInt() // check if frequency is within dog's hearing range if (67 <= frequency && frequency <= 45000) { println("YES, the dog can hear this frequency.") } else { println("NO, the dog cannot hear this frequency.") } // close scanner object scanner.close() }

Practical 1.1.2 Aim:- Let's assume there is one fest name VIBES and you want to visit with your friend. You manage to collect passes for fest. A person can enter the fest using one pass, and each pass can be used by only one person. Take two input one no. of passes you have and Second no. of you are. Print YES if all person enter in the fest with available passes otherwise print NO. Note:- In Second Input You are excluded.

Code in Kotlin: import java.util.Scanner fun main() { // create scanner object to take input from user val scanner = Scanner(System.in) // take input from user print("Enter the number of passes you have: ") val numPasses = scanner.nextInt() print("Enter the number of friends you have (excluding yourself): ") val numFriends = scanner.nextInt() // check if all friends can enter the fest with available passes if (numPasses >= numFriends) { println("YES, all friends can enter the fest with available passes.") } else { println("NO, all friends cannot enter the fest with available passes.") } // close scanner object scanner.close() }

Practical 1.1.3 Aim:- A participant can make 1 submission every 30 seconds. If a contest lasts for X minutes, what is the maximum number of submissions that the participant can make during it?

fun main() { val minutes = 60 // set the contest duration in minutes val submissionsPerMinute = 2 // participant can make 2 submissions per minute val maxSubmissions = submissionsPerMinute * minutes println("Maximum submissions: $maxSubmissions") }

Practical 1.1.4 Aim:- A lamp is Off and can be on print if the lamp is on or off

import java.util.*

fun main() { println("Lamp is ON or OFF?") val sc = Scanner(System.in) val isStatus = sc.nextLine() if(isStatus == "ON" || isStatus == "on") { println("Lamp is ON") } else if(isStatus.lowercase() == "off") { println("Lamp is OFF") } else { println("Invalid Status") } }

Practical 1.1.3 Aim:- A participant can make 1 submission every 30 seconds. If a contest lasts for X minutes, what is the maximum number of submissions that the participant can make during it? Code:-

import java.util.* fun main() { var xMinute = Scanner(System.in).nextInt() println("Total No of submission are " + xMinute*2) }

Practical 1.1.4 Aim:- Take input from user and print multiplication table upto user input no. Code:-

import java.util.* fun main() { var no = Scanner(System.in).nextInt() for(i in 1..no){ for(j in 1..10){ println("$i * $j = " + i*j) } println("") } }

kotlin-example's People

Contributors

vaibhavproject-1 avatar

Watchers

 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.