Using Numbers

This sample code shows how to declare variables and assign values to them. Then print out the result of a calculation.

import java.awt.*;
import java.applet.Applet;

public class Adder extends Applet {

public void paint (Graphics g) {

int a=50; //declare variables and assign values to them
int b=11;
int answer;
answer = a+b; //calculate the result
g.drawString(a+" + "+b+" = "+answer, 50,50); //print the result

}

}

The output is:

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License