CS001 Introduction to Programming Day 6

8
CS001 Introduction to Programming Day 6 Sujana Jyothi (sujana @cs.nuim.ie )

description

CS001 Introduction to Programming Day 6. Sujana Jyothi ( sujana @cs.nuim.ie ). What will you learn today?. Learn to write programs Use the Java programming language. File HelloTester.java. public class HelloTester { - PowerPoint PPT Presentation

Transcript of CS001 Introduction to Programming Day 6

Page 1: CS001 Introduction to Programming Day 6

CS001Introduction to Programming

Day 6

CS001Introduction to Programming

Day 6

Sujana Jyothi([email protected])

Page 2: CS001 Introduction to Programming Day 6

2

What will you learn today?

• Learn to write programs• Use the Java programming

language

Page 3: CS001 Introduction to Programming Day 6

3

File HelloTester.java

public class HelloTester {

public static void main(String[] args) { // Display a greeting in the console window System.out.println(“hello, world"); } }

public class HelloTester {

public static void main(String[] args) { // Display a greeting in the console window System.out.println(“hello, world"); } }

Outputhello, worldhello, world

Page 4: CS001 Introduction to Programming Day 6

Statement

System.out.println(“hello, world”);

Page 5: CS001 Introduction to Programming Day 6

Example in Java

Page 6: CS001 Introduction to Programming Day 6

// Program to find the average of three numberspublic class Average{ public static void main(String[] args) { int number1 = 5; int number2 = 4; int number3 = 7; int sum = number1+number2+number3; int average = sum/3; System.out.println(“Sum is " + sum); System.out.println(" Average is" + average); } }

Page 7: CS001 Introduction to Programming Day 6

Program to find if the first number is greater than or less than or equal to the second number

public class Maximum { public static void main(String[] args) {

int x = 10; int y = 20; // complete this }}

Page 8: CS001 Introduction to Programming Day 6

// Program Multiples calculates the square and cube of a value public class Multiples{ public static void main(String[] args) { int VALUE = 5; System.out.println("The number is " + VALUE); int VALUE1 = VALUE*VALUE; System.out.println(“squared is " + VALUE1); int VALUE2 = VALUE*VALUE*VALUE; System.out.println(" cubed is " + VALUE2); } }