Beruflich Dokumente
Kultur Dokumente
En este Ejercicio, se va a declarar e inicializar un a variable. Tambin se muestra cmo modificar y mostrar el valor de una variable.
1. Construir (Build) y ejecutar (Run) el programa Java OutputVariable utilizando NetBeans IDE
2. Construir (Build) y ejecutar (Run) el programa Java OutputVariable utilizando los comandos "javac" y "java"
(1.1) Construir (Build) y ejecutar (Run) el programa Java OutputVariable utilizando NetBeans IDE
Pulsar en Next.
En la seccin Name and Location, del campo Project Name, escribir MyOutputVariableProject. Este es el nombre que se le da al
nuevo proyecto creado con NetBeans.
En el campo Create Main Class, escribir OutputVariable. (Figura-1.10) Esto es para crear OutVariable.java, en el que el mtodo
main(..) ser creado de forma automtica.
Observe que el nodo del proyecto MyOutputVariableProject se crea bajo el panel Projects del IDE NetBeans y que el
fichero OutputVariable.java se muestra en la ventana del editor del IDE.
Modificar el OutputVariable.java como se muestra en Cdigo-1.11 y la Figura-1.12 de abajo. Los fragmentos de cdigo que necesitan
ser agregados esn resaltados en negrita y color azul.
/*
* OutputVariable.java
*
* Created on January 19, 2010, 6:30 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
/**
*
* @author
*/
public class OutputVariable {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// Variable value is int primitive type and it is initialized to 10
int value = 10;
// Variable x is char primitive type and it is initialized to 'A'
char x;
x = 'A';
// Variable grade is a double type
double grade = 11;
// Display the value of variable "value" on the standard output device
System.out.println( value );
//Display the value of variable "x" on the standard output device
System.out.println( "The value of x=" + x );
// Display the value of variable "grade" on the standard output device
System.out.println( "The value of grade =" + grade );
}
}