Created
December 2, 2025 03:52
-
-
Save hikaMaeng/5e25b1f2b2d78f115316d54dc604640f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.example.demo | |
| import org.springframework.boot.autoconfigure.SpringBootApplication | |
| @SpringBootApplication | |
| class DemoApplication | |
| fun main(args: Array<String>) { | |
| val p1 = Person("초기이름1", "초기성1") | |
| val p2 = Person("초기이름2", "초기성2") | |
| p1.firstName = "기완" | |
| p1.familyName = "맹" | |
| p1.age = 1 | |
| p2.firstName = "현경" | |
| p2.familyName = "권" | |
| p2.age = 1 | |
| p1.showMe() | |
| p2.showMe() | |
| } | |
| class Person(f: String, n: String){ | |
| var firstName: String = f | |
| var familyName: String = n | |
| var age: Int = 0 | |
| fun fullName() = "${this.firstName} $familyName" | |
| fun showMe() { | |
| println("${fullName()}: $age") | |
| } | |
| init{ | |
| if(n.isEmpty() && " " in f){ | |
| val s = f.split(" ") | |
| familyName = s[s.lastIndex] | |
| firstName = s.dropLast(1).joinToString(" ") | |
| }else{ | |
| firstName = f | |
| familyName = n | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment