Java Programming
In Code3 there are (6) numbered items. The first four are "compiler errors." Include a separate Word document with your assignment and explain why each will produce a compiler error and what you would do to fix the problem. Explain what is happening in 5 and 6 and why this code will prevent a possible compiler error.
// This program illustrates the use of Java datatypes.
import java.io.*;
import java.lang.*;
public class Code3
{ //begins Nums
public static void main(String args[])
{
int x= 5;
int y= 2;
int z = 0;
long a, b = 0;
double d= 5.12345;
byte c = 0;
//float e = 34.2; compiler error: (1)
float e = 34.2F; //or float e = (float) 34.2;
short f,g,h;
f =2; g = f;
//h = f * g; compiler error (2)
//c = a; compiler error (3)
//z = 5L; compiler error (4)
a = 6; //promotion of int too long
b = 1000L;
z = (int) (5000L + b); // (5)
c = (byte) (x*y); // (6)
a = c;
System.out.println(c);
System.out.println(c * a);
System.out.println(b);
z = (int) d; // lose decimal places
System.out.println(z);
} //end main
} //end Nums
By OTA: Abdun Mahmood, PhD
OTA Rating: 4.9/5
Your Price: $2.19 (original value ~$3.99)
What's included:
Page generated in 0.0227 seconds