Question1: Please fix all the errors in the code below
public class Homework1 {
public static void main(String[] args) {
int i1 = 10; // line1
double d1 = 5.0; // line2
float f1 = 2.05; // line3
char c1 = i1; // line4
short s1 = c1; // line5
float f2 = d1 / f1; // line6
double d2 = f1 + i1 + c1; // line7
float f3 = d1 - i1; // line8
byte b1 = 3; // line9
byte b2 = 4; // line10
byte b3 = 2 * b1 - b2; // line11
}
}
Question2: (25 points) Calculate the value of d1 and d2:
int i = 15;
int j = 10;
float f1 = 2;
float d1 = i / j;
float d2 = i / f1;
d1 =
d2 =
Question 3:
What is the value of a, b, i, j after the statements below are excuted.
int a = 10;
int b = 5;
int i = ++a
int j = b--;
a =
b =
i =
j=
Question 4:
What's the difference between continue and break?
Question 5:
public class Example {
public static void main(String[] args) {
int i = 1;
while (i <= 10) {
i = i + 2;
System.out.print(i + " ");
}
}
}
Output:
Question 6:
public class Example {
public static void main(String[] args) {
for (int k = 20; k >=10; k = k -3) {
System.out.print(k + " ");
}
}
}
Output:
Question 7:
Please give an example to show value returning method and void method.