You are on page 1of 3

1.

Source Code:
public class Main

public static void main(String []args)

System.out.println("//This is a single-line comment//");

System.out.println("/*This is a single-line comment*/");

Output:

2. Create a variable named carName and assign the value Volvo to it.
Source code:
public class Main

public static void main(String []args)

String carName="Volvo";

System.out.println(carName);

}
Output:

3. Create a variable named maxSpeed and assign the value 120 to it..
Source code:
public class Main

public static void main(String []args)

int maxSpeed=120;

System.out.println(maxSpeed);

Output:

4. Display the sum of 5 + 10, using two variables: x and y.


Source code:
public class Main

public static void main(String []args)

int x=5;

int y=10;

int sum=x+y;

System.out.println(sum);

}
Output:

5. Create a variable called z, assign x + y to it, and display the result.


Source code:
public class Main

public static void main(String []args)

String z="x+y";

System.out.println(z);

Output:

6.

You might also like