2012年12月1日土曜日

開発環境

『初めてのプログラミング 第2版』(Chris Pine 著、長尾 高弘 訳、オライリー・ジャパン、2010年、ISBN978-4-87311-469-9)の 2章(数値), 2.5(練習問題)1年の時間数 を解いてみる。

その他参考書籍

1年の時間数

コード(TextWrangler)

sample.rb

#!/usr/bin/env ruby1.9
# -*- coding: utf-8 -*-

puts "#{365 * 24}時間"
puts "(うるう年の場合#{366 * 24}時間)"

入出力結果(Terminal)

$ ./sample.rb
8760時間
(うるう年の場合8784時間)
$

ちなみにJavaScriptの場合。

コード(TextWrangler)

var result = 365 * 24 + "時間\n" + 
  "(うるう年の場合" + 366*24 + "時間)\n";
$('#pre0').text(result);



pythonの場合。

sample.py

コード(TextWrangler)

#!/usr/bin/env python3.3
# -*- coding: utf-8 -*-

print("{0}時間".format(365*24))
print("(うるう年の場合{0}時間)".format(366*24))
$

入出力結果(Terminal)

$ ./sample.py
8760時間
(うるう年の場合8784時間)
$

perlの場合。

sample.pl

コード(TextWrangler)

#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use 5.016;
binmode STDIN, ':utf8';
binmode STDOUT, ':utf8';

print 365 * 24, "時間\n";
print "(うるう年の場合", 366*24 , "時間)\n";

入出力結果(Terminal)

$ ./sample.pl
8760時間
(うるう年の場合8784時間)
$

0 コメント:

コメントを投稿