CS001 Introduction to Programming Day 6 Sujana Jyothi
2 What will you learn today? Learn to write programs Use the Java programming language
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"); } } Output hello, world
Statement System.out.println(“hello, world”);
Example in Java
// 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); }