public class Shape2D { // define super class public double area() { // all Shape2D have their own area return 0; } } public class Rectangle extends Shape2D { private double length, width; public Rectangle(double l, double w) { // define constructor length = l; width = w; } public double area() { // Override return length * width; } } public class Circle extends Shape2D { private double radius; public Circle(double r) { radius = r; } public double area() { // Override return 3.141592654 * radius * radius; } } public class Parallelogram extends Shape2D { private double top, bottom, height; public Parallelogram(double t, double b, double h) { top = t; bottom = b; height = h; } public double area() { // Override return (top + bottom) * height / 2.0; } } publicclass Main { public static double sum(Shape2D[] shapes) { double total = 0; for (int i = 0; i < shapes.length; i++) { total += shapes[i].area(); // use Virtual Function to calculate area of Shape2D // Without Virtual Function, value of Shape2D.area() will be 0 } return total; } public static void main(String[] argv) { Shape2D[] data; // array of reference to Shape2D data = new Shape2D[5]; // create array object data[0] = new Rectangle(2.4, 3.8); // Polymorphism data[1] = new Circle(3.9); data[2] = new Parallelogram(3.5, 6.7, 10.2); data[3] = new Rectangle(5.3, 7.2); data[4] = new Circle(4.6); System.out.println("Sum of all Shape2D is "+sum(data)); } }
override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } // MARK: - Table view data source override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { // Return the number of rows in the section. return self.restaurantNames.count } override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cellIdentifier = "Cell" let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! CustomTableViewCell // Configure the cell... cell.nameLabel.text = restaurantNames[indexPath.row] cell.thumbnailImageView.image = UIImage(named: restaurantImages[indexPath.row]) cell.locationLabel.text = restaurantLocations[indexPath.row] cell.typeLabel.text = restaurantTypes[indexPath.row] cell.accessoryType = restaurantIsVisited[indexPath.row] ? .Checkmark : .None // Circular image cell.thumbnailImageView.layer.cornerRadius = cell.thumbnailImageView.frame.size.width / 2 cell.thumbnailImageView.clipsToBounds = true return cell }
先到範本>編輯HTML
在<head></head>之間插入:
<script src='https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js?lang=css&skin=sunburst'/>
儲存
不知為何上面的連結過幾天就沒效果了,可以試試看下面,是我從官網抓的,後來換這就可以了:
<script defer='defer' src='https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js?autoload=true&lang=css&lang=ml&skin=sunburst'/>
再到範本>自訂>進階>新增CSS
插入這段:
.prettyprint.linenums ol li, pre.prettyprint.linenums ol li {//這是讓每行程式都顯示行號 list-style: decimal; } .post .prettyprint { //設定程式碼區塊 overflow-x:auto; overflow-y:auto; max-height:800px;//max-height設定區塊高度 white-space:pre;//保留原始空白與換行 }現在只要在pre tag裡插入程式碼即可:
<pre class="prettyprint linenums"> code................. </pre>原本上面程式區塊我做不出來,這時就要把特殊符號轉碼了,請到這個網站,像<>這樣的特殊符號就要轉碼,轉出來再放到pre tag裡,像上面如果我要顯示<pre class="prettyprint linenums">怎麼做?你想,很簡單,就一樣插到pre tag,不就變成pre tag裡還有一個pre tag?我試過,這樣不行,所以才要轉碼。
參考資料:
https://github.com/google/code-prettify
http://sheep801note.blogspot.tw/2015/09/blogger-code.html
http://rj-memo.blogspot.tw/2015/05/blogger_23.html http://chaoyunotebook.blogspot.tw/2015/09/blogger.html
http://blog.shihshih.com/google-code-prettify/
http://eric0806.blogspot.tw/2014/04/blogger-google-code-prettify.html
SyntaxHighlighter
沒有留言:
張貼留言