Primera entrega Tarea

parents
# Default ignored files
/shelf/
/workspace.xml
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Kotlin2JvmCompilerArguments">
<option name="jvmTarget" value="1.8" />
</component>
<component name="KotlinCommonCompilerArguments">
<option name="apiVersion" value="1.4" />
<option name="languageVersion" value="1.4" />
</component>
</project>
\ No newline at end of file
<component name="libraryTable">
<library name="KotlinJavaRuntime">
<CLASSES>
<root url="jar://$KOTLIN_BUNDLED$/lib/kotlin-stdlib.jar!/" />
<root url="jar://$KOTLIN_BUNDLED$/lib/kotlin-reflect.jar!/" />
<root url="jar://$KOTLIN_BUNDLED$/lib/kotlin-test.jar!/" />
<root url="jar://$KOTLIN_BUNDLED$/lib/kotlin-stdlib-jdk7.jar!/" />
<root url="jar://$KOTLIN_BUNDLED$/lib/kotlin-stdlib-jdk8.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$KOTLIN_BUNDLED$/lib/kotlin-stdlib-sources.jar!/" />
<root url="jar://$KOTLIN_BUNDLED$/lib/kotlin-reflect-sources.jar!/" />
<root url="jar://$KOTLIN_BUNDLED$/lib/kotlin-test-sources.jar!/" />
<root url="jar://$KOTLIN_BUNDLED$/lib/kotlin-stdlib-jdk7-sources.jar!/" />
<root url="jar://$KOTLIN_BUNDLED$/lib/kotlin-stdlib-jdk8-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="KotlinJavaRuntime (2)">
<CLASSES>
<root url="jar://$KOTLIN_BUNDLED$/lib/kotlin-stdlib.jar!/" />
<root url="jar://$KOTLIN_BUNDLED$/lib/kotlin-reflect.jar!/" />
<root url="jar://$KOTLIN_BUNDLED$/lib/kotlin-test.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$KOTLIN_BUNDLED$/lib/kotlin-stdlib-sources.jar!/" />
<root url="jar://$KOTLIN_BUNDLED$/lib/kotlin-reflect-sources.jar!/" />
<root url="jar://$KOTLIN_BUNDLED$/lib/kotlin-test-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_15" project-jdk-name="15" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/Tarea_1.iml" filepath="$PROJECT_DIR$/Tarea_1.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
<mapping directory="$PROJECT_DIR$/../repo" vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/kotlin" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/kotlin" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
<orderEntry type="library" name="KotlinJavaRuntime (2)" level="project" />
</component>
</module>
\ No newline at end of file
//Ejercicio 10
fun main(){
println(contarValoresUnicos(listOf(2,3,4,5,6,2,2,3)))
}
fun contarValoresUnicos(lista : List<Int>): Int{
//por implementacion
var rep : Boolean = true
var cant : Int = 1
for (i in 1 until lista.size){
rep = true
for(k in i-1 downTo 0){
if(lista[i]==lista[k]){
rep =false
}
}
if(rep){
cant++
}
}
return cant
}
\ No newline at end of file
//Ejercicio 11
fun main(){
println(top2PalabrasLargas("Hola que tal estas amigo"))
}
fun top2PalabrasLargas(cadena : String): List<String> {
var partes = cadena.split(" ")
var mayor1 = partes[0]
var mayor2 = partes[0]
for( i in partes){
if(i.length>mayor1.length){
mayor2=mayor1
mayor1=i
}else if(i.length>mayor2.length){
mayor2=i
}
}
return listOf(mayor1,mayor2)
}
//Ejercicio 12
fun main(){
println(esPalindromo("abBA"))
}
//Ejercicio 12
fun esPalindromo(cadena: String):Boolean{
return cadena.equals(cadena.reversed(), ignoreCase = true)
}
//Ejercicio 13
fun main(){
println(esPalindromo2("awba"))
println(esPalindromo2("a@abaa"))
}
//Ejercicio 13
fun esPalindromo2(cadena: String):Boolean{
var cad : String = ""
var error : Int = 0
var cont : Int =0
for (i in cadena.indices){
cad=""
for (k in cadena.indices){
if(i==k) continue
cad+=cadena[k]
}
if(esPalindromo(cad)){
return true
}
}
return false
}
\ No newline at end of file
//Ejercicio 14
fun main(){
println(contarVocales("hola viejos"))
}
fun contarVocales(cadena:String): Int{
val vocales : String="aeiou"
var cant : Int = 0
for(letra in cadena){
if(vocales.contains(letra)){
cant++
}
}
return cant
}
//Ejercicio 15
fun main(){
println(cifrar("zzz",2))
}
fun cifrar (cadena:String, desplazamiento:Int):String{
var codigo :String =""
var pos : Int =0
val letras : String = "abcdefghijklmnopqrstuvwxyz"
var cod = desplazamiento%letras.length
for (i in cadena){
pos=letras.indexOf(i)
if(pos+cod>=letras.length){
pos=cod-1
}else{
pos+=cod
}
codigo+="${letras[pos]}"
}
return codigo
}
\ No newline at end of file
//Ejercicio 16
fun main(){
println(descrifrar("aaa",52))
}
fun descrifrar(cadena: String, desplazamiento: Int):String{
var codigo :String =""
var pos : Int =0
val letras : String = "abcdefghijklmnopqrstuvwxyz"
var cod = desplazamiento % letras.length
for (i in cadena){
pos=letras.indexOf(i)
if(pos-cod<0){
pos=letras.length-cod
}else{
pos-=cod
}
codigo+="${letras[pos]}"
}
return codigo
}
\ No newline at end of file
//Ejercicio 3
fun main(){
val N =5
println(sumaFilaNrosImpares(N))
}
fun sumaFilaNrosImpares(N:Int):Int{
var inicio =1
var sum =0
for(i in 2..N){
inicio+=2*(i-1)
}
for (k in 1..N){
sum+= inicio+2*(k-1)
}
return sum
}
//Ejercicio 4
fun main(){
println(capitalizarTexto("hola que tal"))
println(capitalizarTexto("Hola Que Tal"))
}
fun capitalizarTexto(cadena:String) :String {
//por funciones cadena.capitalize()
//por implementacion
var cad : String = ""
var bandera =1
for(i in cadena){
if(' ' == i){
cad+="$i"
bandera=1
}else if(bandera==1 && i!=' '){
cad +="${i.toUpperCase()}"
bandera = 0
}else{
cad+="$i"
}
}
return cad
}
\ No newline at end of file
//Ejercicio 5
fun main(){
println("${obtenerImpares(listOf(2,3,4,5,6))}")
}
fun obtenerImpares(lista: List<Int>) : Int?{
var cant : Int =0
for(i in lista){
if(i%2!=0){
cant++
}
}
return if(cant==0){
null
}else {
cant
}
}
\ No newline at end of file
//Ejercicio 6
fun main(){
println(sumarHasta(4))
}
fun sumarHasta(n:Int) :Int{
var suma=0
for(i in 1..n){
suma+=i
}
return suma
}
//Ejercicio 7
fun main(){
cuentaRegresiva(5)
}
fun cuentaRegresiva(n:Int) {
for(i in n downTo 0){
print("$i ")
}
print("\n")
}
//Ejercicio 8
fun main(){
contar(5)
}
fun contar(n:Int){
cuentaRegresiva(n)
for(i in 0..n){
print("$i")
}
print("\n")
}
\ No newline at end of file
//Ejercicio 9
fun main(){
llamarLista(listOf("Juan","Pablo","Ruben"))
llamarLista(listOf("Rossana"))
}
fun llamarLista(lista: List<String>) {
print("Llamando lista a ")
if(lista.size == 1){
print(lista[0])
}
for((index,nombre) in lista.withIndex()){
if(index<lista.size-2){
print("$nombre, ")
}
else if(index==lista.size-2){
print("$nombre y ")
}else{
print(nombre)
}
}
}
\ No newline at end of file
fun main(args: Array<String>) {
}
//Ejercicio 16
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment