Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% encontró este documento útil (0 votos)
55 vistas2 páginas

PROG02 Ejerc10

Descargar como txt, pdf o txt
Descargar como txt, pdf o txt
Descargar como txt, pdf o txt
Está en la página 1/ 2

package com.mycompany.

PROG02_Ejerc10;

import java.util.Scanner;

/**
*
* @author PC
*/
public class PROG02_Ejerc10 {

public static void main(String[] args){


float x=4.5f;
float y=3.0f;
int i=2;
float j=x*i;

double dx=2.0;
double dz=dx*y;
byte bx=5;
byte by=2;
byte bz=(byte)(bx-by);
System.out.println("Producto de int por float: j=i*x = "+(int)j);
System.out.println("Producto de float por double: dz=dx*y = "+dz);

System.out.println("======Operaciones con byte======");


System.out.println("Byte 5-2 = "+bz);

bx=(byte)-128;
by =(byte)1;
bz =(byte)(bx-by);
System.out.println("Byte -128-1 = "+bz);
bx=(int)-128;
by=(int)-1;
System.out.println("(int)(-128-1)= "+(int)(bx+by));
System.out.println("======Operaciones con short======");
short sx=5;
short sy=2;
short sz=(short)(sx-sy);
System.out.println("10-1"+sz);
sx=32767;
sy=1;
sz=(short)(sx+sy);
System.out.println("short 32767 + 1 = "+sz);

System.out.println("======Operaciones con char======");


char cx = '\u000F';
char cy = '\u0001';
int z=(int)(cx-cy);
System.out.println("char: -="+z);

z=(char)(cx-1);
System.out.println("char(0x000F)-1 = "+z);

cx= '\uFFFF';
z=(int)cx;
System.out.println("(int)()="+z);
sx=(short)cx;
System.out.println("(short)()= "+sx);
sx=-32768;
System.out.println("-32768 short-char-int ="+(sx*(-1)));

cx=(char)sx;//cx es char y sx es -1 short


z=sx; //z ahora es -1
sx=-1;//-1 igual a -1
cx=(char)sx;//cx igual a ?
z=cx;
System.out.println("-1 short-char-int ="+z);
}

También podría gustarte