kotlin函数

news2024/10/2 14:24:19

一、Main函数

fun printHello() {
     println("Hello World")
 }
 printHello()
Hello World

在main的函数中,执行播放按钮,会编译执行,结果在下面显示:
在这里插入图片描述

1.1 Basic Task

  1. Create a new Kotlin file.
  2. Copy and paste the main() function from Hello World into the file.
  3. Create a new function, dayOfWeek().
  4. In the body of the function, print “What day is it today?”
  5. Call dayOfWeek() from main().
  6. Run your program.
fun main(args: Array<String> ){
    println("Hello World!")
    dayOfWeek()
}

fun dayOfWeek() {
    print("What day is it today?")
}

1.2 Extended Task

In the body of the dayOfWeek() function, answer the question by printing the current day of the week.

Hints

  • You can use Java libraries (java.util) from Kotlin. For example, to get the day of the week:
    Calendar.getInstance().get(Calendar.DAY_OF_WEEK)
  • Type in the code, then press Option + Enter in Mac, or Alt + Enter in Windows, over the red Calendar class to import the library.
  • Use a when statement to print a string depending on the day. Sunday is the first day of the week.
import java.util.Calendar

fun main(args: Array<String> ){
    println("Hello World!")
    dayOfWeek()
}

fun dayOfWeek() {
    println("What day is it today?")
    val dayOfWeek = Calendar.getInstance().get(Calendar.DAY_OF_WEEK)
//    print(dayOfWeek)
    when(dayOfWeek) {
        1 -> println("Monday")
        2 -> println("Tuesday")
        3 -> println("Wednesday")
        4 -> println("Thursday")
        5 -> println("Friday")
        6 -> println("Saturday")
        7 -> println("Sunday")
    }
}

二、函数参数

fun main(args: Array<String>) {
    println("Hello ${args[0]}")

    val isUnit = println("This is an expression")
    println(isUnit)

    val temperature = 10
    val isHot = if (temperature > 50) true else false
    println(isHot)
    
    val message = "You are ${ if (temperature > 50) "fried" else "safe" } fish"
    println(message)
}

2.1 Greetings, Kotlin

Exercise: Greetings, Kotlin

Create a main() function that takes an argument representing the time in 24-hour format (values between and including 0 -> 23).

In the main() function, check if the time is before midday (<12), then print “Good morning, Kotlin”; otherwise, print “Good night, Kotlin”.

Notes:

Remember that all main() function arguments are Strings, so you will have to convert this argument to an Int before you can apply the check.

fun main(args: Array<String>)
{
    if( args[0].toInt() < 12) {
        println("Good morning,Kotlin")
    } else if( args[0].toInt() in 12..24) {
        println("Good night,Kotlin")
    } else {
        println("Error time")
    }

    println("Good ${if(args[0].toInt() > 12) "night" else "morning"},Kotlin")
}

三、随机日子喂鱼

import java.util.*

fun main(args: Array<String> ){
    println("Hello World!")
    feedTheFish()
}

fun feedTheFish() {
    val day = randomDay()
    val food = "pellets"
    println("Today is $day and fish eat $food")
}

fun randomDay() : String {
    val week = listOf("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")
    return week[Random().nextInt(7)]
}

3.1 练习

Create a program with a function that returns a fortune cookie message that you can print.

  1. Create a main() function.
  2. From the main() function, call a function, getFortuneCookie(), that returns a String.
  3. Create a getFortuneCookie() function that takes no arguments and returns a String.
  4. In the body of getFortuneCookie(), create a list of fortunes. Here are some ideas:
    • “You will have a great day!”
    • “Things will go well for you today.”
    • “Enjoy a wonderful day of success.”
    • “Be humble and all will turn out well.”
    • “Today is a good day for exercising restraint.”
    • “Take it easy and enjoy life!”
    • “Treasure your friends because they are your greatest fortune.”
  5. Below the list, print: "Enter your birthday: "
    • Hint: Use print(), not println()
  6. Create a variable, birthday.
  7. Read the user’s input form the standard input and assign it to birthday. If there is no valid input, set birthday to 1.
    • Hint: Use readLine() to read a line of input (completed with Enter) as a String.
    • Hint: In Kotlin, you can use toIntOrNull() to convert a number as a String to an Integer numeric. If the user enters “”, toIntOrNull returns null.
    • Hint: Check for null using the ? operator and use the ?: operator to handle the null case.
  8. Divide the birthday by the number of fortunes, and use the remainder as the index for the fortune to return.
  9. Return the fortune.
  10. In main(), print: "Your fortune is: ", followed by the fortune string.
    Extra practice:
    Use a for loop to run the program 10 times, or until the “Take it easy” fortune has been selected.
fun main(args:Array<String>)
{
    var fortune = getFortuneCookie()
    println("Your fortune is:$fortune")
}

fun getFortuneCookie() : String
{
    val fortunesList:Array<String> = arrayOf("You will have a great day!",
        "Things will go well for you today.", "Enjoy a wonderful day fo success.",
        "Be humble and all will turn out well.", "Today is good day for exercising restraint.",
        "Take it easy and enjoy life!", "Treasure your friends because they are your greatest fortune.")

    print("enter your birthday:")
    var birthday:Int = readLine()?.toIntOrNull()?:1
    var fortuneNum:Int = birthday.mod(7)
    return fortunesList[fortuneNum];
}


//结果:
//enter your birthday:14
//Your fortune is:You will have a great day!

3.2 extra练习:

fun main(args:Array<String>)
{
    //var fortuneNum = getFortuneCookie()
    //println("Your fortune is:${fortuneNum}")
    var fortune: String
    for(i in 1..10) {
        fortune = getFortuneCookie()
        println("Your fortune is: $fortune")
        if(fortune.contains("Take it easy")) break
    }

}

fun getFortuneCookie() : String
{
    val fortunesList:Array<String> = arrayOf("You will have a great day!",
        "Things will go well for you today.", "Enjoy a wonderful day fo success.",
        "Be humble and all will turn out well.", "Today is good day for exercising restraint.",
        "Take it easy and enjoy life!", "Treasure your friends because they are your greatest fortune.")

    print("enter your birthday:")
    var birthday:Int = readLine()?.toIntOrNull()?:1
    var fortuneNum:Int = birthday.rem(fortunesList.size)
    return fortunesList[fortuneNum];
}

四、when函数可以简化

fun fishFood(day: String) : String {
    var food = "fasting"

    return when(day) {
        "Monday" -> food = "flakes"
        "Tuesday" -> food = "pellets"
        "Wednesday" -> food = "redworms"
        "Thursday" -> food = "granules"
        "Friday" -> food = "mosquitoes"
        "Saturday" -> food = "lettuce"
        "Sunday" -> food = "plankton"
    }
    return food
}
//可以改成
fun fishFood(day: String) : String {
    return when(day) {
        "Monday" -> "flakes"
        "Tuesday" -> "pellets"
        "Wednesday" -> "redworms"
        "Thursday" -> "granules"
        "Friday" -> "mosquitoes"
        "Saturday" -> "lettuce"
        "Sunday" -> "plankton"
        else -> "fasting"
    }
}

4.1 练习习题

Use the code you created in the last practice, or copy the starter code from below.

The getFortune() function should really only be getting the fortune, and not be in the business of getting the birthday.

Change your Fortune Cookie program as follows:

Create a function called getBirthday() that gets the birthday from the user.
Pass the result of getBirthday() to getFortune() using an Integer argument, and use it to return the correct fortune.
Remove getting the birthday from getFortune()
Instead of calculating the fortune based on the birthday, use a when statement to assign some fortunes as follows (or use your own conditions):
If the birthday is 28 or 31…
If the birthday is in the first week…
else … return the calculated fortune as before.
Hint: There are several ways in which to make this when statement. How much can you Kotlinize it?

Starter Code:

fun main(args: Array) {
var fortune: String
for (i in 1…10) {
fortune = getFortune(getBirthday())
println(“\nYour fortune is: $fortune”)
if (fortune.contains(“Take it easy”)) break;
}
}

fun main(args:Array<String>)
{
    var fortune: String
    for(i in 1..10) {
        fortune = getFortune(getBirthday())
        println("Your fortune is: $fortune")
        if(fortune.contains("Take it easy")) break
    }

}

fun getFortune(birthday: Int) : String
{
    val fortunesList:Array<String> = arrayOf("You will have a great day!",
        "Things will go well for you today.", "Enjoy a wonderful day fo success.",
        "Be humble and all will turn out well.", "Today is good day for exercising restraint.",
        "Take it easy and enjoy life!", "Treasure your friends because they are your greatest fortune.")
    val index = when(birthday) {
        in 28..31 -> 3
        1,7 -> 2
        else -> birthday.rem(fortunesList.size)
    }
    return fortunesList[index];
}

fun getBirthday(): Int {
    print("enter your birthday:")
    return readLine()?.toIntOrNull() ?: 1
}

5. 函数参数可以有默认值

fun swim(speed: String = "fast") {
    println("swimming $speed")
}
//调用swim()时,如果没有参数,就是fast
//也可以混合,可以多个参数,可以指定

5.1 练习

Exercise: Fit More Fish
Create a function that checks if we can add another fish into a tank that already has fish in it.

How many fish in a tank?
The most widely known rule for stocking a tank is the one-inch-per-fish-per-gallon-of-water rule. However that’s assuming the tank doesn’t have any decorations in it.

Typically, a tank with decorations can contain a total length of fish (in inches) less than or equal to 80% of the tank size (in gallons). A tank without decorations can contain a total length of fish up to 100% of the tank size.

For example:
A 10 gallon tank with decorations can hold up to 8 inches of fish, for example 4 x 2-inch-long fish.
A 20 gallon tank without decorations can hold up to 20 inches of fish, for example 6 x 1-inch-long fish and 2 x 2-inch-long fish.
fitMoreFish function
Create a function that takes these arguments:

tankSize (in gallons)
currentFish (a list of Ints representing the length of each fish currently in the tank)
fishSize (the length of the new fish we want to add to the tank)
hasDecorations (true if the the tank has decorations, false if not)
You can assume that typically a tank has decorations, and that a typical fish is 2 inches long. That means you can set those values as default parameters.

Output
Make sure you test your code against the following calls, and that you get the correct output for each.

canAddFish(10.0, listOf(3,3,3)) —> false
canAddFish(8.0, listOf(2,2,2), hasDecorations = false) —> true
canAddFish(9.0, listOf(1,1,3), 3) —> false
canAddFish(10.0, listOf(), 7, true) —> true

import java.util.*

fun main() {
    println(canAddFish(10.0, listOf(3,3,3)))
    println(canAddFish(8.0, listOf(2,2,2), hasDecorations = false))
    println(canAddFish(9.0, listOf(1,1,3), 3))
    println(canAddFish(10.0, listOf(), 7, true))
}

fun canAddFish(tankSize:Double, currentFish:List<Int>, fishSize:Int = 2, hasDecorations:Boolean = true): Boolean
{
    return ((tankSize * if(hasDecorations) 0.8 else 1.0 )>= (currentFish.sum() + fishSize))
}

Practice Time
Create a program that suggests an activity based on various parameters.

Start in a new file with a main function.
From main(), create a function, whatShouldIDoToday().
Let the function have three parameters.
mood: a required string parameter
weather: a string parameter that defaults to “sunny”
temperature: an Integer parameter that defaults to 24 (Celsius).
Use a when construct to return some activities based on combinations of conditions. For example:
mood == “happy” && weather == “Sunny” -> “go for a walk”
else -> “Stay home and read.”
Copy/paste your finished function into REPL, and call it with combinations of arguments. For example:
whatShouldIDoToday(“sad”)
> Stay home and read.

fun main()
{
    println(whatShouldDoToday("sad"))
}

fun whatShouldDoToday(mood:String, weather: String = "Sunny", temperature:Int=24) : String
{
    return if(mood == "happy" && weather == "Sunny") "go for a walk"
    else "Stay home and read."
}

Improve your whatShouldIDoToday() program with the new knowledge from this segment.

Add 3 more situations and activities. For example:
mood == “sad” && weather == “rainy” && temperature == 0 -> “stay in bed”
temperature > 35 -> “go swimming”
Create a single-expression function for each condition and then use it in your when expression.
Challenge
Instead of passing in the mood, get a mood string from the user.

Hint: The !! operator may come handy.

Loops
This lesson introduced the while and repeat loops. To practice using them, do the following:

Change your fortune cookie program to use repeat() instead of a for loop. What happens to the break instruction? Using the error message from the compiler, with what you’ve learned so far, can you think of why?
Change your fortune cookie program to use a while loop, which is the better choice when you are looping until a condition is met.

fun main()
{
    println(whatShouldDoToday("sad"))
    println(whatShouldDoToday("sad", "rainy", 0))
    println(whatShouldDoToday(weather = "rainy", temperature = 0))
}

fun getMood() = "sad"

fun whatShouldDoToday(mood:String = getMood(), weather: String = "Sunny", temperature:Int=24) : String
{
    return when {
        mood == "happy" && weather == "Sunny" -> "go for a walk"
        mood == "sad" && weather == "rainy" && temperature == 0 -> "stay in bed"
        temperature > 35 -> "go swimming"
        else -> "Stay home and read."
    }
}

使用循环的练习

fun main(args:Array<String>)
{
    var fortune: String = ""
//    repeat(10) {
        while(!fortune.contains("Take it easy")) {
//    for(i in 1..10) {
        fortune = getFortune(getBirthday())
        println("Your fortune is: $fortune")
//        if(fortune.contains("Take it easy")) break
    }

}

fun getFortune(birthday: Int) : String
{
    val fortunesList:Array<String> = arrayOf("You will have a great day!",
        "Things will go well for you today.", "Enjoy a wonderful day fo success.",
        "Be humble and all will turn out well.", "Today is good day for exercising restraint.",
        "Take it easy and enjoy life!", "Treasure your friends because they are your greatest fortune.")
    val index = when(birthday) {
        in 28..31 -> 3
        1,7 -> 2
        else -> birthday.rem(fortunesList.size)
    }
    return fortunesList[index];
}

fun getBirthday(): Int {
    print("enter your birthday:")
    return readLine()?.toIntOrNull() ?: 1
}

六、过滤

fun main()
{
    val list = listOf("abc", "ghf", "aaa", "tur")
    println(list.filter { it[0] == 'a' })
//    eagerExample()
//    lazilyExample()
    lazilyMapExample()
}

fun eagerExample() {
    var list = listOf("rock", "pagoda", "plastic", "tur")
    val decorations = list.filter { it[0] == 'p' }
    println(decorations)
}

fun lazilyExample() {
    var list = listOf("rock", "pagoda", "plastic", "tur")
    val decorations = list.asSequence().filter { it[0] == 'p' }
    println(decorations)
    println(decorations.toList())
}

fun lazilyMapExample() {
    println("lazilyMapExample")
    var list = listOf("rock", "pagoda", "plastic", "tur")
    val decorations = list.asSequence().filter { it[0] == 'p' }
    val lazyMap = decorations.asSequence().map {
        println("map $it")
        it
    }
    println("lazyMap:${lazyMap}")
    println("first:${lazyMap.first()}")
    println("all:${lazyMap.toList()}")
}

Practice Time
You can do the following filter exercise in REPL.

Create a list of spices, as follows:
val spices = listOf(“curry”, “pepper”, “cayenne”, “ginger”, “red curry”, “green curry”, “red pepper” )
Create a filter that gets all the curries and sorts them by string length.
Hint: After you type the dot (.), IntelliJ will give you a list of functions you can apply.
Filter the list of spices to return all the spices that start with ‘c’ and end in ‘e’. Do it in two different ways.
Take the first three elements of the list and return the ones that start with ‘c’.
Note: We will be able to do a lot more interesting stuff with filters after you learn about classes and Map.

val spices = listOf("curry", "pepper", "cayenne", "ginger", "red curry", "green curry", "red pepper")

println(spices.filter { it[0] == 'c' && it[it.length-1] == 'e' })
println(spices.filter { it[0] == 'c' && it.endsWith('e')})
println(spices.take(3).filter { it.startsWith('c') })

七、Lambda

{println("Hello")}()
Hello

    val swim = {println("swim\n")}
    swim()
swin

var dirty = 4
 val waterFilter = {dirty: Int -> dirty/2}
 waterFilter(dirty)
res3: kotlin.Int = 2


fun main(args: Array<String> ){
    println("Hello World!")

    var swimDontRun = {println("swim\n")}
    var swimRunDirectly = { println("swim") }()
    var swimRunDirectly2 = run { println("swim") }

    swimDontRun()
    swimRunDirectly
    swimRunDirectly2


    var dirty = 20
    var waterFilter = {dirty:Int -> dirty /2}
    println(waterFilter(dirty))

    val waterFilter2: (Int) -> Int = {abc : Int -> abc + 2}
    val waterFilter3: (Int) -> Int = {abc -> abc + 2 }
    val waterFilter4: (Int) -> Int = { whatever -> whatever*2}

    println(waterFilter2(dirty))
    println(waterFilter3(dirty))
    println(waterFilter4(dirty))
}

Practice Time: Lambdas
Create a lambda and assign it to rollDice, which returns a dice roll (number between 1 and 12).
Extend the lambda to take an argument indicating the number of sides of the dice used for the roll.
If you haven’t done so, fix the lambda to return 0 if the number of sides passed in is 0.
Create a new variable, rollDice2, for this same lambda using the function type notation.

val rollDice = { Random().nextInt(12) + 1 }
val rollDice2 = {sides:Int -> Random().nextInt(sides) + 1}
val rollDice3 = {sides:Int -> if(sides == 0) 0 else Random().nextInt(sides) + 1 }
val rollDice4: (Int) -> Int = {sides -> Random().nextInt(sides) + 1}

Practice Time: Extra Questions
Why would you want to use the function type notation instead of just the lambda?
Create a function gamePlay() that takes a roll of the dice as an argument and prints it out.
Pass your rollDice2 function as an argument to gamePlay() to generate a dice roll every time gamePlay() is called

    val dice = {sides:Int -> Random().nextInt(sides) + 1}
    val rollDice2:(Int) -> Int = {sides:Int -> if(sides == 0) 0 else Random().nextInt(sides) + 1 }
    gamePlay(dice, rollDice2)

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/7457.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Java中方法的注意事项

C有函数&#xff0c;我们Java有方法&#xff01;实参和形参的关系方法重载public static早在初始Java的那一个博客&#xff0c;我好像就给兄弟们说过&#xff0c;在Java中我们把以前认识到的函数叫做是方法&#xff0c;那么如果单单是为了讲一下方法最基本的使用规则&#xff0…

如何从0-1学习渗透测试?

要成为一名渗透测试员&#xff0c;想从基础学习需要先掌握下面这3块&#xff1a;1、学习硬件和网络渗透测试主要涉及网络和部分涉及硬件。2、操作系统和系统架构操作系统和系统架构在渗透测试中起着关键作用。系统操作涉及x86&#xff08;32位&#xff09;和x64&#xff08;64位…

稳定性实践:开关和预案

在稳定性保障中&#xff0c;限流降级的技术方案&#xff0c;是针对服务接口层面的&#xff0c;也就是服务限流和服务降级。这里还有另外一个维度&#xff0c;就是业务维度&#xff0c;所以今天我们就从业务降级的维度来分享&#xff0c; 也就是开关和预案。 如何理解开关和预案…

AI与轨交并行,智慧服务伴乘客出行

“欢迎来到智能客服中心” “请选择您需要的服务” 大部分乘客在地铁站厅总能听见这样的提示音 而发出提示音的 正是智慧升级过后的地铁智能客服服务中心 地铁作为承载万千群众出行的工具 近年客流呈飞速增长态势 因此&#xff0c;轨道交通行业也正积极进行智慧化转型 …

C语言百日刷题第八天

前言 今天是刷题第8天&#xff0c;放弃不难&#xff0c;但坚持一定很酷~ 快来跟我一起刷题吧。刷题第八天目录前言71.打印7层杨辉三角形72.重新排列数组73.冒泡排序74.将数字变成0的操作次数75.四叶玫瑰数71.打印7层杨辉三角形 打印7层杨辉三角形 图案如下&#xff1a; 这个…

外企面试中的7 个 Android Lifecycle 重要的知识点

习惯性的每天都会打开 medium 看一下技术相关的内容&#xff0c;偶然看到一位大佬分享和 Android Lifecycle 相关的面试题&#xff0c;觉得非常的有价值。 在 Android 开发中 Android Lifecycle 是非常重要的知识点。但是不幸的是&#xff0c;我发现很多新的 Android 开发对 A…

准备pmp考试第13天

准备pmp考试第13天 32 31 感觉答案和题目没有关系 感觉答案和题目没有多大关系&#xff0c;题目看越多 错的越多&#xff0c;答案不按照问的回答&#xff0c;跑题了 30 29 28 PMP 激励&#xff1a;为某人采取行动提供了理由。 提高团队参与决策的能力并鼓励他们独立工作。这里面…

go - rune类型

一、简介 rune类型是Go语言的一种特殊数字类型。 rune是类型int32的别名&#xff0c;在所有方面都等急啊于它&#xff0c;用来区分字符值跟整数值。 Go语言通过rune处理中文&#xff0c;支持国际化多语言。 字符串由字符组成&#xff0c;字符的底层由字节组成&#xff0c;而一…

码神之路项目总结(二)

目录 一、登录功能 & 二、获取用户信息& 三、退出登录 四、登录拦截&#xffe5; 五、ThreadLocal保存用户信息&#xffe5; 六、文章详情 一、登录功能 & 请求接口&#xff1a; 思路&#xff1a; 1、首先接收前端传过来的用户名和密码&#xff0c;判断值是否为空…

知识图谱认知智能理论与实战----------第二章 知识图谱模式设计

文章目录一. 知识图谱模式二. 模式与本体三. 本体概论I. 模式与本体辨析II.本体的构成要素III.实体分类IV.实体分类四. 六韬法I. 场景II. 复用III. 事物IV. 联系V. 约束VI. 评价一. 知识图谱模式 实体&#xff1a;eg&#xff1a;法国&#xff0c;巴黎…关系&#xff1a;eg&…

深度学习入门(三十六)计算性能——异步计算、自动并行

深度学习入门&#xff08;三十六&#xff09;计算性能——异步计算、自动并行前言计算性能——异步计算教材1 异步计算1.1 通过后端异步处理1.2 小结2 自动并行2.1 基于GPU的并行计算2.2 并行计算与通信3.3 小结前言 核心内容来自博客链接1博客连接2希望大家多多支持作者 本文…

一起Talk Android吧(第四百一十三回:使用三角函数绘制正弦波)

文章目录整体思路图形讲解示例程序注意事项各位看官们&#xff0c;大家好&#xff0c;上一回中咱们说的例子是"Math类常用方法介绍",这一回咱们介绍的例子是使用三角函数绘制正弦波。闲话休提&#xff0c;言归正转&#xff0c;让我们一起Talk Android吧&#xff01; …

leetcode-每日一题-1710-卡车上的最大单元数(简单,哈希,暴力)

今天的这道题其实很好读懂&#xff0c;因为很容易可以看出来暴力求解&#xff0c;但其实还是隐藏一个hash求解法很巧妙&#xff0c;因为我在很久之前就用过hash解答过这样类似的题&#xff0c;所以这个题也是可以使用的&#xff0c;可以看看我第二个hash解法 目录 暴力效率(效…

SBF vs. 火柴大王

生活中的一切都建立在自信之上。”Ivar Kreuger1929年10月28日&#xff0c;瑞典商人Ivar Kreuger出现在《时代》杂志的封面上。 他是当时美国最受关注的人物之一&#xff0c;因为他富有、有权势、神秘。Kreuger控制着四分之三的火柴生产和销售&#xff0c;在全球35个不同国家拥…

wy的leetcode刷题记录_Day43

wy的leetcode刷题记录_Day40 声明 本文章的所有题目信息都来源于leetcode 如有侵权请联系我删掉! 时间&#xff1a;2022-11-15 前言 今天时间比较多而且题目比较简单&#xff0c;应该能写三四道题。 目录wy的leetcode刷题记录_Day40声明前言1710. 卡车上的最大单元数题目介…

Spectacle源码编译方法

一、简介 Spectacle 是一个用于抓取桌面截图的简单应用程序。它可以抓取整个桌面、单个显示器、当前活动窗口、鼠标所在的窗口或是屏幕上的一块矩形区域的图像。截取的图像可被打印、发送到其他应用程序进行处理、或是直接保存下来。 Spectacle是archlinux wiki中推荐KDE使用…

刘二大人CNN

10.卷积神经网络&#xff08;基础篇&#xff09;_哔哩哔哩_bilibili 0、前一部分 卷积层 和 subsampling 叫做Feature Extraction特征提取器&#xff0c;后一部分叫做classification 1、每一个卷积核它的通道数量要求和输入通道是一样的。这种卷积核的总数有多少个和你输出通…

SpringBoot+Vue项目医院挂号系统的设计与实现

文末获取源码 开发语言&#xff1a;Java 使用框架&#xff1a;spring boot 前端技术&#xff1a;JavaScript、Vue 、css3 开发工具&#xff1a;IDEA/MyEclipse/Eclipse、Visual Studio Code 数据库&#xff1a;MySQL 5.7/8.0 数据库管理工具&#xff1a;phpstudy/Navicat JDK版…

2.6 自定义srv python

功能介绍 以自定义数据类型为基础&#xff0c;完成一个节点作为服务器&#xff0c;另一个节点接收传送两个数字到服务端&#xff0c;服务端计算后反馈到客户端进行打印输出 1、工作空间 1.1 创建工作空间lee_ws mkdir -p ~/lee_ws/src cd ~/lee_ws/src/ catkin_init_worksp…

leetcode134.加油站 贪心法求解 (c++版本)

题目描述 题目比较长&#xff0c;明确以下这点就可以 gas数组是当前下标i加油站所能加的油cost数组是从当前下标i加油站到下一加油站所消耗的油那么gas [i]与cost [i] 的大小就决定了车辆能否从当前加油站出发到达下一加油站 上面三点非常重要是能正确做出题目的必须要求 其实…