home > さまざまな言語で数値計算 > 基本のき >

さまざまな言語で数値計算

Only Do What Only You Can Do

変数の値を表示する

VBScript

Option Explicit

Dim i: i = 3 * 5
WScript.Echo "3 * 5 = " & i
Z:\>cscript //nologo 0102.vbs
3 * 5 = 15

JScript

var i = 3 * 5;
WScript.Echo("3 * 5 = " + i);
Z:\>cscript //nologo 0102.js
3 * 5 = 15

PowerShell

$i = 3 * 5

Write-Host   '3 * 5 = ' $i
Write-Host   '3 * 5 = ', $i
Write-Host   "3 * 5 = $i"

Write-Output "3 * 5 = $i"
Echo         "3 * 5 = $i"
Z:\>powershell -file 0102.ps1
3 * 5 =  15
3 * 5 =  15
3 * 5 = 15
3 * 5 = 15
3 * 5 = 15

Perl

my $i = 3 * 5;
print "3 * 5 = ".$i."\n";
print "3 * 5 = ", $i, "\n";
print "3 * 5 = $i\n";
printf "3 * 5 = %d\n", $i;
Z:\>perl 0102.pl
3 * 5 = 15
3 * 5 = 15
3 * 5 = 15
3 * 5 = 15

PHP

<?php
$i = 3 * 5;
print "3 * 5 = $i\n";
print "3 * 5 = ".$i."\n";

printf("3 * 5 = %d\n", $i);

echo "3 * 5 = $i\n";
echo "3 * 5 = ".$i."\n";
echo "3 * 5 = ", $i, "\n";
?>
Z:\>php 0102.php
3 * 5 = 15
3 * 5 = 15
3 * 5 = 15
3 * 5 = 15
3 * 5 = 15
3 * 5 = 15

Python

i = 3 * 5
print "3 * 5 =", i
print "3 * 5 = %d" % i
Z:\>python 0102.py
3 * 5 = 15
3 * 5 = 15

Ruby

i = 3 * 5
print "3 * 5 = ", i, "\n"
print "3 * 5 = #{i}\n"

printf "3 * 5 = %d\n", i

puts "3 * 5 = #{i}"
Z:\>ruby 0102.rb
3 * 5 = 15
3 * 5 = 15
3 * 5 = 15
3 * 5 = 15

Groovy

Pascal

Program Pas0102(arg);
uses
    SysUtils;
var
    i:integer = 3 * 5;
begin
    writeln(format('3 * 5 = %d', [i]));
end.
Z:\>fpc Pas0102.pp -v0
Free Pascal Compiler version 2.6.2 [2013/02/12] for i386
Copyright (c) 1993-2012 by Florian Klaempfl and others

Z:\>Pas0102
3 * 5 = 15

Ada

VB.NET

Module VB0102
    Public Sub Main()
        Dim i As Integer = 3 * 5
        Console.WriteLine("3 * 5 = " & i)
        Console.WriteLine(String.Format("3 * 5 = {0}", i))
    End Sub
End Module
Z:\>vbc -nologo VB0102.vb

Z:\>VB0102
3 * 5 = 15
3 * 5 = 15

C#

public class CS0102
{
    public static void Main()
    {
        int i = 3 * 5;
        System.Console.WriteLine("3 * 5 = " + i);
        System.Console.WriteLine(string.Format("3 * 5 = {0}", i));
    }
}
Z:\>csc -nologo CS0102.cs

Z:\>CS0102
3 * 5 = 15
3 * 5 = 15

Java

public class Java0102 {
     public static void main(String []args) {
        int i = 3 * 5;
        System.out.println("3 * 5 = " + i);
        System.out.printf("3 * 5 = %d\n", i);
     }
}
Z:\>javac Java0102.java

Z:\>java Java0102
3 * 5 = 15
3 * 5 = 15

C++

#include <iostream.h>

int main()
{
    int i = 3 * 5;
    cout << "3 * 5 = " << i << endl;;
    return 0;
}
Z:\>bcc32 CP0102.cpp
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
CP0102.cpp:
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland

Z:\>CP0102
3 * 5 = 15

Objective-C

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[])
{
    int i = 3 * 5;
    printf("3 * 5 = %d\n", i);
    return 0;
}
Compiling the source code....
$gcc `gnustep-config --objc-flags` -L/usr/GNUstep/System/Library/Libraries -lgnustep-base main.m -o demo -lm -pthread -lgmpxx -lreadline 2>&1

Executing the program....
$demo
3 * 5 = 15

D

Go

Scala

object Scala0102 {
    def main(args:Array[String]) {
        val i = 3 * 5;
        printf("3 * 5 = %d\n", i);
    }
}
Z:\>scala Scala0102.scala
3 * 5 = 15

F#

module Fs0102

let i = 3 * 5
printfn "3 * 5 = %d" i
exit 0
Z:\>fsi Fs0102.fs --nologo

[Loading Z:\Fs0102.fs]
3 * 5 = 15

Clojure

(def i (* 3 5))
(printf "3 * 5 = %d\n" i)
Z:\>java -cp C:\ProgramFiles\clojure-1.5.1\clojure-1.5.1.jar clojure.main Clj0102.clj
3 * 5 = 15

Haskell

import Text.Printf 

main = do
    let i = (3 * 5)::Int
    printf "3 * 5 = %d\n" i
    putStrLn ("3 * 5 = " ++ (show i))
Z:\>runghc Hs0102.hs
3 * 5 = 15
3 * 5 = 15

inserted by FC2 system