100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Other

Brunel - Computer Science - CS1702 Introductory Programming Lab Worksheets

Rating
-
Sold
-
Pages
26
Uploaded on
06-01-2024
Written in
2018/2019

CS1702 Introductory Programming Lab Worksheets

Institution
Course










Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Institution
Study
Unknown
Course

Document information

Uploaded on
January 6, 2024
Number of pages
26
Written in
2018/2019
Type
Other
Person
Unknown

Subjects

Content preview

public class CS1702_Lab2 {

public static void main(String args[])
{
long a,g,x;
double b,c,y;
boolean d;
final double pi;
String e,f,h,z,name;



a=100;
b=2.3;
c=-52.2;
d=true;
e="I am ";
f="a student";
g=0;
h="!";
pi=3.142;
name=" sadiq ";


//Q1
y=a+b;
System.out.println(y);
//Q2
System.out.println("no answer");
//Q3
z=e+f;
System.out.println(z);
//Q4
y = b*c;
System.out.println(y);
//Q5
System.out.println("no answer");
//Q6
System.out.println("no answer");
//Q7
System.out.println("no answer");
//Q8
x=10;
System.out.println(Math.pow(x,3));
//Q9
z=name+" is "+f+h;
System.out.println(z);
//Q10
System.out.println("no answer");
//Q11
System.out.println("no answer");
//Q12
y=100.3;
y=(y/(a + b))-c;
System.out.println(y);
//Q13
System.out.println("no answer");
//Q14
System.out.println("no answer");
//Q15
y=((pi+1)/(pi+2))/(pi+3);
System.out.println(y);
//Q16
y=-2;
System.out.println(Math.pow((Math.pow(y, 2)/b),(1.0/3.0)));
//Q17
System.out.println("no answer");
//Q18
z=name;
z=b/g+z;
System.out.println(z);
//Q19
y=-2.3;
y=a*(Math.pow(y,2))+b*y+c;
System.out.println(y);
//Q20
System.out.print("no answer");




}


}

,1.) 102.3
2.) No answer (Boolean error)
3.) I am a student
4.) -120.06
5.) No answer (pi is constant)
6.) No answer (string / 0)
7.) No answer (z is string)
8.) 1000.0
9.) sadiq is a student!
10.) No answer
11.) No answer
12.) 53.18044965786902
13.) No answer (string)
14.) No answer (cant subtract a char)
15.) 0.13114997439694126
16.) 1.2025709773288682
17.) No answer (cannot divide by 0)
18.) Infinity sadiq
19.) 471.50999999999993
20.) No answer

, CS1702 Introductory Programming (2018-2019)



Laboratory 3 – Week 4
Conditional Statements in Java
3.1 Introduction

The laboratory session covers conditional statements in Java. Again we will be implementing
some of the examples given during the lecture, followed by some additional examples. We
will then look at a few sections of the help pages.

Note that: this worksheet is one of the worksheets from which your laboratory
worksheets portfolio of work will be assessed [CodeRunner tests].

3.2 Relational operators

Create a new project and Java class called CS1702_Lab3. Add the following code:
static public void main(String args[])
{
int a = 1000,b = -22;

if (a < b)
{
System.out.println("a is less than b");
}
else
{
System.out.println("a is NOT less than b");
}
}


Run the program. It should display the message “a is NOT less than b”. Test the program on a
number of different values of a and b such that both parts of the if statement is run. Now
add a similar set of program code that tests if a is greater than b.

Using the above code “snippet” as a basis, write a set of Java if statements that determines if
the following statements are true, note that you must declare the variables first and choose the
correct type.

Let x = 100, y = 204, z = -23.1, a = true, b = false, c = -204

1) x<y
2) x > z and a = b
3) 2c > y
4) x=b
5) c ≠ y or c = y
6) z ≠ y and c = a
7) y ≥ y and a+3 ≠ 2




3/26

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
cslbrunel Brunel University
Follow You need to be logged in order to follow users or courses
Sold
63
Member since
3 year
Number of followers
34
Documents
29
Last sold
4 months ago
Brunel Computer Science (1st Class Honours)

I achieved a First Class Honours degree in Computer Science from Brunel University - I will be uploading some of my work. Please do not purchase any documents looking for the solution to your assignments or deliverables. No refunds / exchanges.

5.0

2 reviews

5
2
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions