Declaración de Variables Java

December 26, 2017 | Author: Anonymous | Category: Java
Share Embed


Short Description

Declaración de Variables Java by jonny_rubio_1 in Types > School Work....

Description

Ejercicio 1: Declarar, inicializar, imprimir variables

En este Ejercicio, se va a declarar e inicializar un a variable. También se muestra cómo 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

0. Iniciar NetBeans IDE si no lo está. 1. Crear el proyecto 

Seleccionar File en el menú superior y seleccionar New Project.



Observar que aparece la ventana de diálogo de New Project.



Seleccionar Java en la sección Categories y Java Application en la sección Projects.



Pulsar en Next.



En la sección 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 método main(..) será creado de forma automática.



Hacer Click en Finish.

Figura-1.10: Creación del proyecto OutVariable 

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.

2. Modificar el fichero generado OutputVariable.java. 

Modificar el OutputVariable.java como se muestra en Código-1.11 y la Figura-1.12 de abajo. Los fragmentos de código que necesitan ser agregados esán 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 ); } }

Código-1.11: Modificación de OutputVariable.java

Figura-1.12: Modificación de OutputVariable.java 3. Construir (Build) y ejecutar (run) el programa 

Seleccionar con el botón derecho MyOutputVariableProject y seleccionar Run.



Observar el resultado en la ventana Output del IDE NetBeans. (Figura-1.13)

Figura-1.13: Resultado de ejecutar el programa OutputVariable

View more...

Comments

Copyright © 2017 DATENPDF Inc.