Gap Analysis for Integrated Atmospheric ECV CLImate Monitoring
Published on Gap Analysis for Integrated Atmospheric ECV CLImate Monitoring (http://www.gaia-clim.eu)

Home > Support > Text format Code Examples

Text format Code Examples

C code example:
//C hello world example
#include <stdio.h>
 
int main()
{
  printf [1]("Hello world\n");
  return 0;
}
C++ code example:
// File name: HelloWorld.cpp
// Purpose:   A simple C++ program which prints "Hello World!" on the screen
 
#include <iostream>  // need this header file to support the C++ I/O system
using namespace std; // telling the compiler to use namespace "std",
		     // where the entire C++ library is declared.
 
int main()
{
        // Print out a sentence on the screen.
        // "<<" causes the expression on its right to 
        // be directed to the device on its left.
        // "cout" is the standard output device -- the screen.
	cout << "Hello World!" <<  endl;
	return 0; // returns 0,which indicate the successful	
		  // termination of the "main" function 
 
}
Java code example:
// This example is from the book _Java in a Nutshell_ by David Flanagan.
// Written by David Flanagan.  Copyright (c) 1996 O'Reilly & Associates.
// You may study, use, modify, and distribute this example for any purpose.
// This example is provided WITHOUT WARRANTY either expressed or implied.
 
import java.applet.*;
import java.awt.*;
 
public class Scribble extends Applet [2] {
    private int last_x = 0;
    private int last_y = 0;
    private Color [3] current_color = Color [3].black;
    private Button [4] clear_button;
    private Choice [5] color_choices;
 
    // Called to initialize the applet.
    public void init() {
        // Set the background color
        this.setBackground(Color [3].white);
 
        // Create a button and add it to the applet.
        // Also, set the button's colors
        clear_button = new Button [4]("Clear");
        clear_button.setForeground(Color [3].black);
        clear_button.setBackground(Color [3].lightGray);
        this.add(clear_button);
 
        // Create a menu of colors and add it to the applet.
        // Also set the menus's colors and add a label.
        color_choices = new Choice [5]();
        color_choices.addItem("black");
        color_choices.addItem("red");
        color_choices.addItem("yellow");
        color_choices.addItem("green");
        color_choices.setForeground(Color [3].black);
        color_choices.setBackground(Color [3].lightGray);
        this.add(new Label [6]("Color: "));
        this.add(color_choices);
    }
 
    // Called when the user clicks the mouse to start a scribble
    public boolean mouseDown(Event [7] e, int x, int y)
    {
        last_x = x; last_y = y;
        return true;
    }
 
    // Called when the user scribbles with the mouse button down
    public boolean mouseDrag(Event [7] e, int x, int y)
    {
        Graphics [8] g = this.getGraphics();
        g.setColor(current_color);
        g.drawLine(last_x, last_y, x, y);
        last_x = x;
        last_y = y;
        return true;
    }
 
    // Called when the user clicks the button or chooses a color
    public boolean action(Event [7] event, Object [9] arg) {
        // If the Clear button was clicked on, handle it.
        if (event.target == clear_button) {
            Graphics [8] g = this.getGraphics();
            Rectangle [10] r = this.bounds();
            g.setColor(this.getBackground());
            g.fillRect(r.x, r.y, r.width, r.height);
            return true;
        }
        // Otherwise if a color was chosen, handle that
        else if (event.target == color_choices) {
            String [11] colorname = (String [11]) arg;
            if (arg.equals("black")) current_color = Color [3].black;
            else if (arg.equals("red")) current_color = Color [3].red;
            else if (arg.equals("yellow")) current_color = Color [3].yellow;
            else if (arg.equals("green")) current_color = Color [3].green;
            return true;
        }
        // Otherwise, let the superclass handle it.
        else return super.action(event, arg);
    }
 
}
JavaScript code example:
<script type="text/javascript">
// Popup window code
function newPopup(url) {
	popupWindow = window.open(
		url,'popUpWindow','height=700,width=800,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')
}
</script>
<p>Popup Window:</p>
<p><a href="JavaScript:newPopup('http://www.quackit.com/html/codes/');">Get your HTML codes in a popup!</a></p>
<div class="more-info">
<p>More info: <a href="/javascript/popup_windows.cfm">Popup Windows</a></p>
</div>
PHP code example:
<!DOCTYPE html>
<html>
<body>
 
<h1>My first PHP page</h1>
 
<?php
echo "Hello World!";
?>
 
</body>
</html>
Python code example:
import re
for test_string in ['555-1212', 'ILL-EGAL']:
    if re.match(r'^\d{3}-\d{4}$', test_string):
        print test_string, 'is a valid US local phone number'
    else:
        print test_string, 'rejected'
Ruby code example:
# Program to find the factorial of a number
# Save this as fact.rb
 
def fact(n)
  if n == 0
    1
  else
    n * fact(n-1)
  end
end
 
puts fact(ARGV[0].to_i)
Public Content [12]

Source URL: http://www.gaia-clim.eu/page/text-format-code-examples

Links
[1] http://www.opengroup.org/onlinepubs/009695399/functions/printf.html
[2] http://www.google.com/search?hl=en&amp;q=allinurl%3Adocs.oracle.com+javase+docs+api+applet
[3] http://www.google.com/search?hl=en&amp;q=allinurl%3Adocs.oracle.com+javase+docs+api+color
[4] http://www.google.com/search?hl=en&amp;q=allinurl%3Adocs.oracle.com+javase+docs+api+button
[5] http://www.google.com/search?hl=en&amp;q=allinurl%3Adocs.oracle.com+javase+docs+api+choice
[6] http://www.google.com/search?hl=en&amp;q=allinurl%3Adocs.oracle.com+javase+docs+api+label
[7] http://www.google.com/search?hl=en&amp;q=allinurl%3Adocs.oracle.com+javase+docs+api+event
[8] http://www.google.com/search?hl=en&amp;q=allinurl%3Adocs.oracle.com+javase+docs+api+graphics
[9] http://www.google.com/search?hl=en&amp;q=allinurl%3Adocs.oracle.com+javase+docs+api+object
[10] http://www.google.com/search?hl=en&amp;q=allinurl%3Adocs.oracle.com+javase+docs+api+rectangle
[11] http://www.google.com/search?hl=en&amp;q=allinurl%3Adocs.oracle.com+javase+docs+api+string
[12] http://www.gaia-clim.eu/content-access/public-content