9月6学习内容


softwore32:swift software32$ vi fpf.swift 
let numberOfStoplights = 4
var population: Int
population = 15422
var unhiredRate: Double = 0.1
let message: String
if popilation <10000{
  message = "\(name) is a small town."
}
else if population <1000{
   message = "\(name) is a medium town."
}
else{
   message = "\(name) is a large town."
}
let description = "name:\(name)\n"
                +"stoplights:\(numberOfStoplights)\n"
~                                                                               
~                                                                               
~                                                                               
~                                                                               
"fpf.swift" 19L, 388C
public class Flips { public static void main(String[] args){ int N = Integer.pareInt(args[0]); Couter heads = new Counter("Head"); Couter tails = new Counter("Tail"); for (int i = 1; i<= N; i++) if (StdRandom.bernoulli(0.5)) heads.increment(); else tails.increment(); Int delte = heads.tally() - tails.tally(); StdOut.println(heads); StdOut.println(tails); StdOut.println("delta:"+delta); }
上课代码2
import edu.printceton.cs.algs4.StdRandom; import edu.printceton.cs.algs4.StdRandom; public class Rolis { public static void main(String[] args){ int N = Integer.parseInt(args[0]); Counter[] counters = new Counter[sides + 1] for (int i = 1; i<=sides;i++) counters[i] = new Counter("" + i); for (int i = 1; i <= N;i++){ int result = new Counter(""+ i ) for (int i = 1; i<=sides;i++) stdOut.println(counters[i]); }
任务累加器
avg'平均数
累加器信息输出。累加多少个数+avg
public class Accumulator { private double sum = 0.0; private int N = 0; public void add(double value){ sum += value; N++; } public double mean(){ if (N == 0 ) return 0; return sum / N; } public String toString(){ return "Mean(" + N + "values):" + String.format("%".3f,mean()); } }
符攀飞 符攀飞
大约 1 个月前
7

扫描下方二维码手机阅读文章

0