80 likes | 159 Views
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 {
E N D
CS001Introduction to ProgrammingDay 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 classHelloTester { public static void main(String[] args) { // Display a greeting in the console windowSystem.out.println(“hello, world"); } } Output hello, world
Statement System.out.println(“hello, world”);
// Program to find the average of three numbers public 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); } }
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 } }
// 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); } }