You are on page 1of 14

Flip class (Using

Java)

Presentation by:
Dr. S. Rajkumar
Associate Professor
School of Computing Science and Engineering
email: rajkumar.srinivasan@vit.ac.in
Room no: AB 4th Floor (Cabin:5)
References
1. Cay S.Horstmann and Gary Cornell, “Core Java: Volume I Fundamentals”, Eighth Edition,
Sun Microsystems Press, 2008.
2. Timothy Budd, “Understanding Object-oriented Programming with Java”, Updated
Edition, Pearson Education, 2000.
3. K.Arnold and J.Gosling, “The Java Programming language”, Third edition, Pearson
Education, 2000.
4. C.Thomas Wu, “An Introduction to Object-Oriented Programming with Java”, Fourth
Edition, TMH, 2006.
5. http://www.javadb.com
6. https://www.jdoodle.com/online-java-compiler/

---------Rajkumar S-----------
Basic algorithms

---------Rajkumar S-----------
Algorithm for swapping of 2 values
Step 1: Read the values of 'a' and 'b'
Step 2: Interchange the values by using the
temporary variable
2.1 temp<-a
2.2 a<-b
2.3 b<-temp
Step 3: Display a and b values.

---------Rajkumar S-----------
Alternative Algorithm for swapping of
2 values
Step 1: Read the values of 'a' and 'b'
Step 2: Interchange the values by using the
following relations:
2.1 a<-a+b
2.2 b<-a-b
2.3 a<-a-b
Step 3: Display a and b values.

---------Rajkumar S-----------
Steps to draft the program
• In linux, type gedit in “search” text field
• Draft the program in text editor
• Save the file using the main classname as the
filename
• Go to terminal for compiling and executing
program

---------Rajkumar S-----------
Example Program-1

---------Rajkumar S-----------

---------Rajkumar S-----------
How to compile and run the program?
(Refer the screen shot)
---------Rajkumar S-----------

---------Rajkumar S-----------

Important note: Main method class name should be used for


saving, compiling
and
running the
Java program
Example program-2

---------Rajkumar S-----------
---------Rajkumar S-----------

Important note: Main method class name should be used for


Saving, compiling
and
running the
Java program
Comment Styles
• Comments are used to clear the logic of the code
and to increase the readability if it.
• Comments are ignored by the compiler.
• Java uses two types of comments:
– Single-line comment(//). Example:
//single-line comment here
– Multiple-line comment(/*…*/). Example:
/*
line 1 here
line 2 here …
*/
---------Rajkumar S-----------
Data types
1. Primitive (or) Intrinsic
Numeric-int,float,byte
Non-numeric-char,boolean
2. Non Primitive (or) Reference
Classes
---------Rajkumar S-----------
Arrays
Interface
How to read the integer value from
the keyboard
import java.util.*;
class Sample{
public static void main(String args[])
{
int a; ---------Rajkumar S-----------

Scanner s=new Scanner(System.in);


a=s.nextInt();
System.out.println(a);
}
}

You might also like