carugnom
4/23/2017 - 12:25 PM

Java

Java

# para Debian Jessie / Ubuntu
echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" | sudo tee /etc/apt/sources.list.d/webupd8team-java.list
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886
sudo apt-get update
sudo apt-get install --install-recommends oracle-java8-installer oracle-java8-set-default

# setear variables de ambiente Java
echo ". /etc/profile.d/jdk.sh" >> ~/.bashrc
// compile .... javac DataTypes.java
// run ........ java DataTypes
public class DataTypes {
  public static void main(String[] args) {

    // para los tipos numericos les asigno el mayor valor posible
    byte varByte = 127;
    short varShort = 32767;
    int varInt = 2147483647;
    long varLong = 9223372036854775807L;
    float varFloat = Float.MAX_VALUE;
    double varDouble = Double.MAX_VALUE;

    System.out.println("byte ..... " + varByte);
    System.out.println("short .... " + varShort);
    System.out.println("int ...... " + varInt);
    System.out.println("long ..... " + varLong);
    System.out.println("float .... " + varFloat);
    System.out.println("double ... " + varDouble);

    /////////////////////////////////////////////////////////////////

    boolean varBoolean = true;
    char varChar = 'C';
    char varCharU = '\u0065';
    String varString = "HOLA";

    System.out.println("boolean .. " + varBoolean);
    System.out.println("char ..... " + varChar);
    System.out.println("charU .... " + varCharU);
    System.out.println("String ... " + varString);
  }
}
// compile .... javac ConsoleIO.java
// run ........ java ConsoleIO
import java.util.Scanner;

public class ConsoleIO {
  public static void main(String[] args) {
    Scanner keyboard = new Scanner(System.in);

    System.out.println("Enter a string");
    String string = keyboard.next();

    System.out.println("Enter an integer");
    int integer = keyboard.nextInt();

    // I could continue trying with nextLong, nextFloat, nextDouble, nextBigInteger, nextBigDecimal
    // but I will not ;-\

    System.out.println("String:  " + string);
    System.out.println("Integer: " + integer);
  }
}