0% found this document useful (0 votes)
9 views11 pages

Java OOP Lab Exercises Fall 2022

The document contains a lab exercise for CENG2003, focusing on object-oriented programming with Java. It includes exercises for correcting Java statements, writing a program to produce specific output, and calculating values from given code snippets. Additionally, it provides a task for creating a program that generates a student's email based on their first and last names.

Uploaded by

taba7111917
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views11 pages

Java OOP Lab Exercises Fall 2022

The document contains a lab exercise for CENG2003, focusing on object-oriented programming with Java. It includes exercises for correcting Java statements, writing a program to produce specific output, and calculating values from given code snippets. Additionally, it provides a task for creating a program that generates a student's email based on their first and last names.

Uploaded by

taba7111917
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

CENG2003 – Object Oriented

Programming with Java

Lab 1

Fall 2022
Java IDE

IntelliJ Idea:
[Link]
Exercise 1

Correct the following statements

(1) boolean isGood = 1;


(2) int 2way = 17;
(3) double #grade = 4.5;
(4) string name = "Zeynep";
(5) int _number = 37.3;
(6) String name = Ali;
(7) int student id = 1234567;
(8) char letter = k;
(9) float score = 1.7;
Correct the following statements

• boolean isGood = 1; • boolean isGood = true;


• int 2way = 17; • int twoWay = 17;
• double #grade = 4.5; • double grade = 4.5;
• string name = "Zeynep"; • String name = "Zeynep";
• int _number = 37.3; • double _number = 37.3;
• String name = Ali; • String name = "Ali";
• int student id = 1234567; • int student_id = 1234567;
• char letter = k; • char letter = 'k';
• float score = 1.7; • float score = 1.7f;
Exercise 2

Write a program that produces the following output.


Exercise 2 - Solution

public class Main {


public static void main(String[] args) {
[Link]("\\Quoted from Huckleberry Finn\\");
[Link]("I broke in and says:");
[Link]("\"They're in an awful peck of trouble, and\"");
[Link]("\"Who is?\"");
[Link]("\"Why, pap and mam and sis and Miss Hooker;");
[Link]("\tand if you'd take your ferryboat and go up there\"");
[Link]("\"Up where? Where are they?\"");
[Link]("\"On the wreck.\"");
[Link]("\"What wreck?\"");
}
}
Exercise 3 - 1

After executing the code below, what are the values of x, y, z and w?
Print these values to the console.

int x, y, z, w;
x = 11;
y = 4;
z = x / ++y;
w = ++x % y--;
Exercise 3 - 2

After executing the code below, what is the value of z?


Print these values to the console.

String x, y, z;
x = "CENG2003";
y = "OOP with Java";
z = x + "-" + y;
Exercise 3 - 3

After executing the code below, what are the values of


• x/y
• y+z
• x–y*z

Print these values to the console.

int x, y;
double z;
x = 1;
y = 5;
z = 2.34;
Exercise 4

Write a Java program that prompts the students for his/her first name
and last name, then display the student's KGTU e-mail account as the
"first_name.last_name@[Link]"

For example, if the user entered "duygu" and "altunkaya", the program
should display "[Link]@[Link]".

Sample Output:
Exercise 4 - Solution

You might also like