Exercise (Solutions)

E1

What is wrong with the following variable declarations?


int x = “24”;
boolean isFun = “true”;
String myname = jayshree;
int my number;
int 24_number = 24;
E2

Write a program to print out if a given number as a program argument is a multiple of 6 or not.

E3

In the below program, you want all the additions to be evaluated first before multiplication and division can happen. How do you fix the code to make that happen?

class MyClass{


    public static void main(String[]args){
        double d = 5 * 6 + 4 + 5 / 3;
        System.out.println(d);
    }
}
E4

What is wrong with the below code?


class MyClass{

    public static void main(String[]args){
        b = 10;
        System.out.println(b);
    }
}
E5

Write a program that prints out the name, street name, city, phone number all on different lines by taking all the inputs, one at a time, by the user using Scanner.

results matching ""

    No results matching ""