C# input output example

This is a little Program written in C sharp with Mono, It reads a number from the Terminal multiplies with itself and then print back:

using System.IO;
using System;

class Program
{
    static void Main()
    {
        Console.Write("write your number: ");//Info text 
        String str = Console.ReadLine();//read input
        Console.WriteLine("your number: "+str);//print input
        int i = Convert.ToInt32(str);//convert to intager
        i = i*i;//calculate
        Console.WriteLine("your result: "+i);//print result
    }
}

To compile run this:

mcs *.cs -out:main.exe

And then start with Mono :

mono main.exe

our result looks like this:

write your number: 4   
your number: 4     
your result: 16

The same Programm in Java is here : Java input output example

Java input output example

This is a little example in Java how to print an info text and then read a number from the terminal, calculate the square and then print the result:

public class HelloWorld{
     public static void main(String []args){
        System.out.print("write your number: ");//Info text 
        String str = System.console().readLine();//read input
        System.out.println("your number: "+str);//print input
        int i = Integer.parseInt(str);//convert to intager
        i = i*i;//calculate
        System.out.println("your result: "+i);//print result
     }
}

To compile your test.java file run this in your terminal:

javac test.java

now we have the file test, to execute run this:

java -Xmx128M -Xms16M test

This is the output:

write your number: 4                                                       
your number: 4                                                               
your result: 16

The same Program in C# is here : C# input output example