zoukankan      html  css  js  c++  java
  • scala实现相邻两个元素挑换位置的代码,哈哈

    import scala.math._
    import breeze.plot._
    import breeze.linalg._
    
    import scala.collection.mutable.ArrayBuffer
    //https://stackoverflow.com/questions/36984780/spark-shell-how-to-use-breeze-viz
    object breeze2 {
      def main(args: Array[String]): Unit = {
      }
    
    
      def pow(x: Double, n: Int): Double = {
        var pw = 1.0.toDouble
        var i = 1
        var m = n
    
        for (j <- 1 to (m / 2) if n % 2 == 0 && x > 0) {
          pw *= x
        }
        for (j <- 1 to m if n % 2 == 1 && x > 0) {
          pw *= x
        }
        for (j <- 1 to m if x < 0) {
          pw *= 1 / x
        }
        pw
      }
    
     // println(pow(3, 4))
    
      val b = ArrayBuffer(1, 7, 2, 9)
      val bSorted = b.sorted
    
      val a = ArrayBuffer(2,3,4,5,6,7)
        val i=0
    for(i<-0 until  a.length)
      { for(j<-1 until a.length if (i==j-1) if(i%2==0))
        { val temp=a(i)
          a(i)=a(j)
          a(j)=temp
        }
    
      }
    
    
       for(t<- a)
         {
           println(a)
         }
    
    
      }
    
  • 相关阅读:
    Python 爬虫一 简介
    linux 基础笔记本
    Celery 分布式任务队列快速入门
    Git & Github
    Python 设计模式
    Python 数据结构
    Python 基础算法
    js2wordcloud 词云包的使用
    lambda 3
    sql server 远程
  • 原文地址:https://www.cnblogs.com/canyangfeixue/p/8385006.html
Copyright © 2011-2022 走看看