Convert to double:
int num = 10;
double data = num;
//To covert into double you'd have to assign to new variable
What is the value of newNum and of i when:
int i = 10;
int newNum = 10 * i;
i= i + 1;
i= 11
newNum= 100
What is the value of item when:
item= item+5;
the value of item would be 5
int, double, and String are _____
data types
Public Static Void Main (String [] args){
}
Syntax error, main method.
public static void main (String [] args){
}
When converting from int to double, are you widening the range or narrowing the range?
You are widening the range.
Remeber that double has a bigger range (biggest overall) than integer.
What is the value of a,b, and c:
int a=11, b=22, c;
c = a + b + a+ b +a +b;
a=11
b=22
c=99
what is the value of:
5/2
This is integer division so the answer would be 2 instead of 2.5
what are the two ways to divide in java?
Explain what they do
/ and the %
int x = 4/0;
Runtime/compile error. 4 divided by 0 will throw an Arithmetic exception
Convert to int:
double num = 10.99;
int data = (int)num;
Will have to assing to a new variable.
int m = 0, n = 1;
m++;
n+=2;
System.out.println(m);
System.out.println(n);
m= 1
n= 3
what is the value of --> int value= 100%5
0 because the % gives you the remainder of a division
a ___ is called the assignment operator because it's used to assign a value to a variable.
the = sign
int div = x/2;
int x= 1;
yes this is a compile time error
When converting from double to int, are you widening the range or narrowing the range?
You are narrowing the range; interger is smaller than double
What is the value of p?
int m = 0, n = 1;
int p = m++ * n++;
System.out.println(p);
The value of p is 0
Because p take the original values of m and n:
so the problem is actually 0*1
What is the value of z when :
int y=+ 5;
int z= y%2;
First 5 is assigned to y,
then y (which is 5) is divided by 2 and since it uses the % method it would only indicate if there is a remainder.
When their is remain it is show as a 1(for int division)
A ______ is known as a final variable
constant
int m = 6, sum;
double r=3.4;
sum = m+r;
System.out.println(sum);
yes this is a logic error, since it gives an inaccurate answer.
Can you convert an integer data type into a String data type?
Yes.
Java can convert Int to String Using the ToString Method
int a = 6; int b = a++;
System.out.println(a);
System.out.println(b);
a = 6; b = ++a;
System.out.println(a); System.out.println(b);
a=7
b=6
a=7
b=7
what is the value of:
byte b = 1000
Wouldn't be able to be assign because this value is too large for this data type; would cause a compile error
What data type has the largest storage size?
Double