Java básico 002. Uso de Scanner(System.in)

Mostrar su nombre, sexo, edad y estado civil, que son ingresados por teclado.

Código Java
package com.java.basic;

import java.util.Scanner;

/**
*
* @author Ariel
*/

public class DatoPersonal {

public static void main(String[] arg){
String nombre = "";
String sexo = "";
int edad=0;
String estadoCivil="";

Scanner dato = new Scanner(System.in);

System.out.print("Ingrese el nombre: ");
nombre = dato.nextLine();

System.out.print("Ingrese el sexo (Másculino - Femenino): ");
sexo = dato.nextLine();

System.out.print("Ingrese Estado Civil: ");
estadoCivil = dato.nextLine();

System.out.print("Ingrese edad: ");
edad = dato.nextInt();

System.out.println("* Nombre: " + nombre);
System.out.println("* Sexo: " + sexo);
System.out.println("* Estado Civil: " + estadoCivil);
System.out.println("* Edad: " + edad);

}

}

No hay comentarios :

Publicar un comentario