100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
Brunel - Computer Science - CS1702 Introductory Programming Lab Worksheets $0.00

Other

Brunel - Computer Science - CS1702 Introductory Programming Lab Worksheets

 3 views  0 purchase
  • Course
  • Institution

CS1702 Introductory Programming Lab Worksheets

Preview 3 out of 26  pages

  • January 6, 2024
  • 26
  • 2018/2019
  • Other
  • Unknown
  • Unknown
avatar-seller
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

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller cslbrunel. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $0.00. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

70055 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
Free
  • (0)