0% found this document useful (0 votes)
8 views

Tutorial

Tutorial Sheet

Uploaded by

warriord876
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Tutorial

Tutorial Sheet

Uploaded by

warriord876
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

T322: ICT102 Introduction to Programming

Tutorial -2

Topic: Java Fundamentals: I/O, Data Types and Operators

Submission: Submit your .java file to Moodle

Description:
This tutorial will introduce you to Java fundamentals such as basic primitive type, operators and I/O.

Exercise 1: Working with assignment statements

First estimate the below expressions manually and then output each on the console using
System.out.println().

Discuss why the outputs are different

a. "This shows the wrong current year: " + (20 +22)


b. "This is the correct year: " + 20 + 22
c. 20+22+ ” The wrong year again "

Exercise 2: I/O Program

Modify the following program so it prints 1 tab between each word and 2 blank line between each
line of text

class MyPrintingProgram
{
public static void main(String[] args)
{
System.out.println("L1 Word1 Word2 Word3");
System.out.print("L2 Word4 Word5 Word6");
System.out.print("\n L3 Word7 Word8 Word9");
}
}

ICT102 Introduction to Programming


Exercise 3: Programming task

Write a program that does the following:

1. Declare 3 variables:
• An int variable ‘qty’
• A double variable ‘price’
• A string variable ‘name’

2. Store quantity , price and name of a product in these variables by assigning literal values
to these variables.

3. The program should display these values on the screen as follows, using a mix of text and
above variables

Product Name is TheProduct, its price is $45


You bought 150 quantity.

Submission Task – (Grade 1%)

Follow the same steps as in Exercise 3, but change the step 2 to ask the user for input for these
values by using Scanner class.

ICT102 Introduction to Programming

You might also like