各言語のよく使う構文覚書

#はじめに
すぐ忘れるので。少しずつ書き溜めていくつもりです。
扱っているのは `C#`, `Java`, `Scala`, `JavaScript`, `Python3`, `PHP` です。
`Scala` 初心者のため、どうせならまとめてみようと思ったのが切欠です。

サンプルへのリンク先はJavaScriptが『[JSFiddle](http://jsfiddle.net/)』で、他は『[Ideone](http://ideone.com/)』を利用。
環境構築はこちらを参考に：[各言語の環境構築と簡易確認と腕試し - Qiita](https://qiita.com/rrryutaro/items/b30fdd61d299ef92735a)

#入出力
##Hello World
- [C#：Hello World](https://ideone.com/W4KOPM)
 
```c#:C#
using System;
class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Hello " + Console.ReadLine() + "!");
    }
}
```
- [Java：Hello World](https://ideone.com/zwGmdM)
 
```java:Java
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        System.out.println("Hello " + sc.next() + "!");
    }
}
```
- [Scala：Hello World](https://ideone.com/wwgmSx)

```scala:Scala
object Main extends App {
    println("Hello " + readLine + "!");
}
```

- [JavaScript：Hello World](https://jsfiddle.net/rrryutaro/u9m4jmfs/)

```javascript:JavaScript
function Main(input) {
  alert('Hello ' + input + '!');
}
Main('World');
```
- [Python3：Hello World](https://ideone.com/6bsfSR)

```python:Python3
print("Hello " + input() + "!")
```
- [PHP：Hello World](https://ideone.com/co0uMV)

```php:PHP
<?php
fscanf(STDIN, "%s", $s);
echo "Hello " . $s . "!";
```
#配列操作
##初期化
- [C#：配列の初期化](https://ideone.com/iPAbYM)
 
```c#:C#
int[] ary1 = {1, 2, 3};
int[,] ary2 = {{11, 12, 13}, {21, 22, 23}, {31, 32, 33}};
int[][] ary3 = {new int[]{11, 12, 13}, new int[]{21, 22, 23}, new int[]{31, 32, 33}};
```
- [Java：配列の初期化](https://ideone.com/iPAbYM)

```java:Java
int ary1[] = {1, 2, 3};
int ary2[][] = {{11, 12, 13}, {21, 22, 23}, {31, 32, 33}};
```
- [Scala：配列の初期化](https://ideone.com/37gdbI)

```scala:Scala
var ary1 = Seq(1, 2, 3);
var ary2 = Seq(Seq(11, 12, 13), Seq(21, 22, 23), Seq(31, 32, 33));
```

- [JavaScript：配列の初期化](https://jsfiddle.net/rrryutaro/j9rb7tcu/)

```javascript:JavaScript
var ary1 = [1, 2, 3];
var ary2 = [[11, 12, 13], [21, 22, 23], [31, 32, 33]];
```
- [Python3：配列の初期化](https://ideone.com/8THJbw)

```python:Python3
ary1 = [1, 2, 3]
ary2 = [[11, 12, 13], [21, 22, 23], [31, 32, 33]]
```
- [PHP：配列の初期化](https://ideone.com/S37fmX)

```php:PHP
$ary1 = [1, 2, 3];
$ary2 = [[11, 12, 13], [21, 22, 23], [31, 32, 33]];
```

# ファイル操作
## 入出力
- C#：ファイル入出力

```c#:C#
using System.IO;
using System.Text;

var text = File.ReadAllText(@"C:\hoge1.txt", Encoding.UTF8);
var lines = File.ReadAllLines(@"C:\hoge1.txt", Encoding.UTF8);

File.WriteAllText(@"C:\hoge2.txt", "ほげ", Encoding.UTF8);
File.WriteAllLines(@"C:\hoge2.txt", lines, Encoding.UTF8);
```
- Java：ファイル入出力

```java:Java
import java.util.List;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.charset.StandardCharsets;

List<String> lines = Files.readAllLines(Paths.get("C:\\hoge1.txt"), StandardCharsets.UTF_8);

Files.write(Paths.get("c:\\hoge2.txt"), lines, StandardCharsets.UTF_8);
Files.write(Paths.get("c:\\hoge3.txt"), "ほげ".getBytes(StandardCharsets.UTF_8));
```
- Scala：ファイル入出力

今の所Javaと同じ方法以外でより良い方法は知らない。

- [JavaScript：ファイル入出力](https://jsfiddle.net/rrryutaro/L5as1npj/)

色々と見よう見まね。

```html:html
<form>
  <input type="file" id="file"/><br>
  <textarea id="write"></textarea><br>
  <a id="download" href="#" download="hoge.txt">ダウンロード</a>
</form>
```

```javascript:JavaScript
document.getElementById("file").addEventListener('change', f => {
  var reader = new FileReader();
  reader.readAsText(f.target.files[0]);
  reader.addEventListener( 'load', () => {
    document.getElementById("write").value = reader.result;
  });
});
document.getElementById("download").addEventListener('click', () => {
  var text = document.getElementById("write").value;
  var blob = new Blob([ text ], { "type" : "text/plain" });
  document.getElementById("download").href = window.URL.createObjectURL(blob);
});
```
- Python3：ファイル入出力

```python:Python3
text = open('C:\hoge1.txt', 'r', encoding='utf-8').read()
open('C:\hoge2.txt', 'w', encoding='utf-8').write('ほげ')
```
- PHP：ファイル入出力

```php:PHP
$text = file_get_contents('C:\hoge1.txt');
file_put_contents('C:\hoge2.txt', 'ほげ');
```

# 随時追加
結構面倒なので、少しずつ追加していこう・・・

- [C#：随時追加]()

```c#:C#
```
- [Java：随時追加]()

```java:Java
```
- [Scala：随時追加]()

```scala:Scala
```
- [JavaScript：随時追加]()

```javascript:JavaScript
```
- [Python3：随時追加]()

```python:Python3
```
- [PHP：随時追加]()

```php:PHP
```