INDEX SL.NO NAME OF PROGRAMS PAGE NO REMARKS PROGRAM TO FIND FACTORIAL OF THREE

Similar documents
UNIT - V. Inheritance Interfaces and inner classes Exception handling Threads Streams and I/O

Practical 1 Date : Statement: Write a program to find a factorial of given number by user. Program:

B.Sc (Computer Science) Programming in Java Lab Programs

Prasanth Kumar K(Head-Dept of Computers)

/* Program that accepts a shopping list of five items from the command line and stores them in a vector */

d. If a is false and b is false then the output is "ELSE" Answer?

An applet is a program written in the Java programming language that can be included in an HTML page, much in the same way an image is included in a

Recursive Problem Solving

Exp 6: Develop Java programs to implement Interfaces and Packages. Apply Exception handling and implement multithreaded programs.

Birkbeck (University of London) Software and Programming 1 In-class Test Mar 2018

AN IMPROTANT COLLECTION OF JAVA IO RELATED PROGRAMS

Some Practice Midterm Problems

1)Write a program on inheritance and check weather the given object is instance of a class or not?

MYcsvtu Notes. Java Programming Lab Manual

JAVA PROGRAM EXAMPLE WITH OUTPUT PDF

AP COMPUTER SCIENCE A

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

Assignment2013 Please use this document only for verifying if your programs are right. Do not blindly copy paste and waste your time.

Chapter 7: Iterations

Mobile Application Development ( IT 100 ) Assignment - I

Tutorial 8 Date: 15/04/2014

Vidyalankar. T.Y. Diploma : Sem. V [CO/CM/IF] Java Programming Time : 3 Hrs.] Prelim Question Paper Solution [Marks : 100

Loops. CSE 114, Computer Science 1 Stony Brook University

ICSE Class 10 Computer Applications ( Java ) 2012 Solved Question...

Developed By Strawberry

CMSC 331 Second Midterm Exam

I pledge by honor that I will not discuss this exam with anyone until my instructor reviews the exam in the class.

Week 9. Abstract Classes

1. Java is a... language. A. moderate typed B. strogly typed C. weakly typed D. none of these. Answer: B

1. Download the JDK 6, from

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

(2½ hours) Total Marks: 75

Program 20: //Design an Applet program to handle Mouse Events. import java.awt.*; import java.applet.*; import java.awt.event.*;

OBJECT ORIENTED PROGRAMMING AND DATA STRUCTURES. Inheritance

Chapter 10: Recursive Problem Solving

F I N A L E X A M I N A T I O N

CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE

e) Implicit and Explicit Type Conversion Pg 328 j) Types of errors Pg 371

CIS 1068 Program Design and Abstraction Spring2016 Midterm Exam 1. Name SOLUTION

1. Find the output of following java program. class MainClass { public static void main (String arg[])

Decisions: Logic Java Programming 2 Lesson 7

Java Applet Basics. Life cycle of an applet:

CSC 1051 Algorithms and Data Structures I. Final Examination May 12, Name

Java for Interfaces and Networks (DT3010, HT11)

Review. Primitive Data Types & Variables. String Mathematical operators: + - * / % Comparison: < > <= >= == int, long float, double boolean char

University of Palestine. Mid Exam Total Grade: 100

Lara Technologies Special-Six Test

Methods (Deitel chapter 6)

Methods (Deitel chapter 6)

Full file at Chapter 2 - Inheritance and Exception Handling

UNIT -IV INHERITANCE, PACKAGES AND INTERFACES

WINTER 12 EXAMINATION Subject Code : Model Answer Page No : 01/31

B2.52-R3: INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING THROUGH JAVA

B.Sc (Computer Science) Object Oriented Programming with Java and Data Structures Lab Programs

/ Download the Khateeb Classes App

Special Exercise Unit: Introduction to Java

Introduction to Java

Recursion. General Algorithm for Recursion. When to use and not use Recursion. Recursion Removal. Examples

COMPUTER APPLICATIONS

Tools : The Java Compiler. The Java Interpreter. The Java Debugger

Java Applet & its life Cycle. By Iqtidar Ali

Exercise 4: Loops, Arrays and Files

Road Map. Introduction to Java Applets Review applets that ship with JDK Make our own simple applets

Course Outline. Introduction to java

Java for Interfaces and Networks (DT3029)

4. Finding & Displaying Record of Salesman with minimum net income. 5. Finding & Displaying Record of Salesman with maximum net income.

Full download all chapters instantly please go to Solutions Manual, Test Bank site: testbanklive.com

Course overview: Introduction to programming concepts

CSC 1051 Algorithms and Data Structures I. Final Examination May 12, Name: KEY. Question Value Score

CSE 114 Computer Science I

Third Year Diploma Courses in Computer Science & Engineering, Computer Engineering, Computer Technology & Information Technology Branch.

PART A. input as command line argument. 1. Write a program to find factorial of list of number reading

Java Applets. Last Time. Java Applets. Java Applets. First Java Applet. Java Applets. v We created our first Java application

Getting Started in Java. Bill Pugh Dept. of Computer Science Univ. of Maryland, College Park

Prashanth Kumar K(Head-Dept of Computers)

UNIT - II Object Oriented Programming - Inheritance

CSIS 10A Practice Final Exam Solutions

EE219 - Semester /2009 Solutions Page 1 of 10

15CS45 : OBJECT ORIENTED CONCEPTS

1.00 Introduction to Computers and Engineering Problem Solving. Quiz 1 March 7, 2003

6 COMPUTER PROGRAMMING

Recitation: Loop Jul 7, 2008

A sample print out is: is is -11 key entered was: w

CORBA Java. Java. Java. . Java CORBA. Java CORBA (RMI) CORBA ORB. . CORBA. CORBA Java

1. What is the difference between a compiler and an interpreter? Also, discuss Java s method.

CS/B.TECH/CSE(New)/SEM-5/CS-504D/ OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70 GROUP A. (Multiple Choice Type Question)

AP CS Unit 8: Inheritance Exercises

package import public class public static void int out new for break else out else out

The Java programming environment. The Java programming environment. Java: A tiny intro. Java features

CLASSES AND OBJECTS. BASIC PRINCIPLES OF OOP 1. Data Encapsulation 2. Data Hiding 3. Inheritance 4. Polymorphism DEFINING A CLASS

Chapter 3. Selections

WOSO Source Code (Java)

CT 229 Arrays in Java

S.E. Sem. III [CMPN] Object Oriented Programming Methodology

COMPUTER SCIENCE PAPER 1

AP CS Unit 3: Control Structures Notes

Exception class Hierarchy

1.Which four options describe the correct default values for array elements of the types indicated?

CS Computers & Programming I Review_01 Dr. H. Assadipour

Java - Applets. public class Buttons extends Applet implements ActionListener

Transcription:

INDEX SL.NO NAME OF PROGRAMS PAGE NO REMARKS PROGRAM TO FIND FACTORIAL OF THREE 1 NUMBERS PROGRAM FOR SUM OF SERIES USING 2 MATHPOWER METHOD 3 PROGRAM ON COMMAND LINE ARGUMENT 4 PROGRAM TO PRINT FIBONACI NUMBERS 5 PROGRAM ON CONSOLE INPUT AND OUTPUT PROGRAM TO PRINT MULTIPLICATION 6 TABLE USING NESTED DO WHILE STATEMENT PROGRAM TO FIND LARGEST OF THREE 7 NUMBERS USING NESTING OF IF ELSE STATEMENT PROGRAM TO FIND AREA OF A ROOM USING 8 METHOD OVERLOADING PROGRAM TO FIND AREA AND VOLUME OF 9 A ROOM USING SINGLE INHERITANCE PROGRAM TO OBTAIN MARKS OF A 10 STUDENT IN DIFFERENT FIELDS USING INTERFACE 11 PROGRAM ON OVERRIDING METHODS 12 PROGRAM ON CONSTRUCTORS PROGRAM FOR CREATING OBJECTS AND 13 ACCESSING MEMBERS 14 PROGRAM FOR STATIC MEMBERS 15 NUMBER SORTING USING ARRAY PROGRAM ON MULTITHREADING WHICH 16 SHOWES 5,7 AND 13 TABLE 17 PROGRAM ON EXCEPTION HANDLING 18 19 20 PROGRAM FOR DRAWING HUMAN FACE USING GRAPHICS PROGRAM TO OBTAIN SUM OF TWO NUMBERS USING APPLET PROGRAM TO SHOW CROSS LINES USING GRAPHICS APPLET

1) PROGRAM TO FIND FACTORIAL OF THREE NUMBERS. public class Factorial int fact(int n) if (n<=1) return 1; else return(n * fact(n-1)); public static void main (String arg[]) int fa,fb,fc; int a=4,b=5,c=6; Factorial f; f= new Factorial(); fa= f.fact(a); fb=f.fact(b); fc=f.fact(c); System.out.println("Factorial of " + a+ " is " +fa); System.out.println("Factorial of " + b+ " is " +fb); System.out.println("Factorial of " + c+ " is " +fc); Out put Factorial of 4 is 24 Factorial of 5 is 120 Factorial of 6 is 720

2) PROGRAM FOR SUM OF SERIES USING MATH POWER METHOD. public class Sum public static void main (String arg[]) int n=10; int i=0; int sum=0; int x=2; while(i<n) sum += Math.pow(x,i); i++; System.out.println( "Sum of the series 1 + X+X^2+X^3+...="+sum); Output Sum of the series 1 + X+X^2+X^3+...=1023

3) PROGRAM ON COMMAND LINE ARGUMENT. class Comline public static void main(string args[]) int count, i=0; String string; count= args.length; System.out.println(" Number of arguments = " + count); while(i<count) string = args[i]; i=i+1; System.out.println(i+ " : " + " java is " + string + "!"); Out put C:\J2SDK1~1.0\bin>javac Comline.java C:\J2SDK1~1.0\bin>java Comline Simple Robust secure Portable Number of arguments = 4 1 : java is Simple! 2 : java is Robust! 3 : java is secure! 4 : java is Portable!

4) PROGRAM TO PRINT THE FIBONACI SERIES. import java.io.*; public class Fibo /** Prompt user for a value of n, then print n Fibonacci numbers */ public static void main(string[] args) throws IOException BufferedReader rd = new BufferedReader (new InputStreamReader(System.in)); System.out.print("Enter value of n: "); String ns = rd.readline(); int n = Integer.parseInt(ns); int p = 0, c = 1, a; while (n-- > 0) System.out.println(c); a = p + c; p = c; c = a; Out put Enter value of n: 8 1 1 2 3 5 8 13 21

5) PROGRAM ON CONSOLE INPUT AND OUTPUT import java.io.*; public class Helloi public static void main(string[] args) throws IOException String name; BufferedReader kb = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Please enter your name: "); name = kb.readline(); System.out.println("Hello " + name + "!"); System.out.println("Well come to the world of JAVA!"); System.exit(0); Out put Please enter your name: Shivani Hello Shivani! Well come to the world of JAVA

6) PROGRAM TO PRINT MULTIPLICATION TABLE USING NESTED DO WHILE STATEMENT class DowhileTest public static void main(string args[]) int row,column,y; System.out.println("Multiplication table\n"); row=1; do column=1; do y=row*column; System.out.print(""+y); column= column+1; while(column<=3); System.out.println("\n"); row=row+1; while(row<=3); Output Multiplication table 123 246 369

7) PROGRAM TO FIND LARGEST OF THREE NUMBERS USING NESTING OF IF ELSE STATEMENT class IfElseNesting public static void main(string args[]) int a=325,b=712,c=478; System.out.print("Largest value is :"); if(a>b) if (a>c) System.out.print(a); else System.out.print(c); else if(c>b) System.out.print(c); else System.out.print(b); Out put Largest value is: 712

8) PROGRAM TO FIND AREA OF A ROOM USING METHOD OVERLOADING class Room float length, breadth; Room(float x, float y) length=x; breadth=y; Room(float x) length=breadth=x; float area() return( length * breadth); class moverload public static void main(string args[]) Room room1= new Room(25.0f,15.0f); float roomarea=room1.area(); System.out.println("RoomArea = " +roomarea); Output Room Area = 375.0

9) PROGRAM TO FIND AREA AND VOLUME OF A ROOM USING SINGLE INHERITANCE class Room int length,breadth; Room(int x, int y) length=x; breadth=y; int area() return( length * breadth); class BedRoom extends Room int height; BedRoom(int x, int y, int z) super(x,y); height=z; int volume() return(length *breadth * height); class SingleInher public static void main(string args[]) BedRoom room1= new BedRoom(14,12,10); int area1 = room1.area(); int volume1= room1.volume(); System.out.println("Area1 = " +area1);

System.out.println("Volume1= " +volume1); Output Area1 = 168 Volume1= 1680

10) PROGRAM TO OBTAIN MARKS OF A STUDENT IN DIFFERENT FIELDS USING INTERFACE class Student int rollnumber; void getnumber(int n) rollnumber=n; void putnumber() System.out.println(" Roll No :" + rollnumber); class Test extends Student float part1,part2; void getmarks(float m1, float m2) part1=m1; part2=m2; void putmarks() System.out.println("Marks obtained"); System.out.println("part1=" + part1); System.out.println("part2=" + part2); interface Sports float sportwt = 6.0F; void putwt();

class Results extends Test implements Sports float total; public void putwt() System.out.println("Sports Wt= " +sportwt); void display() total=part1+part2+sportwt; putnumber(); putmarks(); putwt(); System.out.println("Total score = " + total); class Hybrid public static void main(string args[]) Results student1 = new Results(); student1.getnumber(1234); student1.getmarks(27.5f, 33.0F); student1.display(); Output Roll No :1234 Marks obtained part1=27.5 part2=33.0 Sports Wt= 6.0 Total score = 66.5

11) PROGRAM ON OVERRIDING METHODS class Super int x; Super(int x) this.x=x; void display() System.out.println("Super X = " +x); class Sub extends Super int y; Sub(int x, int y) super(x); this.y=y; void display() System.out.println("Super X = " +x); System.out.println("Super Y = " +y); class OverrideTest public static void main(string args[]) Sub s1= new Sub(100,200); s1.display(); Out Put Super X = 100 Super Y = 200

12 PROGRAM ON CONSTRUCTORS class Rectangle int length,width; Rectangle(int x, int y) length=x; width=y; int rectarea() return( length*width); class RectangleArea public static void main(string args[]) Rectangle rect1=new Rectangle(15,10); int area1=rect1.rectarea(); System.out.println("Area1 = " +area1); Output Area1 = 150

13) PROGRAM FOR CREATING OBJECTS AND ACCESSING MEMBERS class Rectangle int length,width; void getdata(int x, int y) length=x; width=y; int rectarea() int area= length*width; return(area); class RectArea public static void main(string args[]) int area1,area2; Rectangle rect1=new Rectangle(); Rectangle rect2= new Rectangle(); rect1.length=15; rect1.width=10; area1=rect1.length*rect1.width; rect2.getdata(20,12); area2=rect2.rectarea(); System.out.println("Area1 = " +area1); System.out.println("Area2 = " +area2); OutPut Area1 = 150 Area2 = 240

14) PROGRAM FOR STATIC MEMBERS class MathOperation static float multi (float x,float y) return x*y; static float divide (float x, float y) return x/y; class MathApplication public static void main(string args[]) float a =MathOperation.multi(4.0f, 5.0f); float b = MathOperation.divide(a, 2.0f); System.out.println("b= " +b); Output b= 10.0

15) PROGRAM FOR NUMBER RSORTING USING ARRAY class NumberSorting public static void main(static void main(string args[]) int number[]=55,40,80,65,71; int n = number.length; System.out.println("Given List: ); for(int i=0;i<n;i++) System.out.print(" "+numbe[i]); System.out.println("\n"); for(int i=0;i<n;i++) for(int j=i+1;j<n;j++) if(number[i]<number[j]) int temp=number[i]; number[i]=number[j]; number[j]=temp; System.out.println("Sorted List:"); for(int i=0;i<n;i++) System.out.println(" " + number[i]); System.out.println(" ");

OutPut Given List: 55 40 80 65 71 Sorted List: 80 71 65 55 40

16) PROGRAM ON MULTITHREADING WHICH SHOWES 5,7 AND 13 TABLE class FiveTable extends Thread public void run() for(int i=1;i<=5;i++) System.out.println(i+ " Fives are " +(i*5)); class SevenTable extends Thread public void run() for(int i=1;i<=5;i++) System.out.println(i+ " Sevens are " +(i*7)); class ThirteenTable extends Thread public void run() for(int i=1;i<=5;i++) System.out.println(i+ " Thirteens are " +(i*13)); class MultiThreading public static void main(string args[]) FiveTable five; SevenTable seven; ThirteenTable thirteen; five= new FiveTable(); seven = new SevenTable(); thirteen = new ThirteenTable();

five.start(); seven.start(); thirteen.start(); Output 1 Fives are 5 1 Sevens are 7 1 Thirteens are 13 2 Fives are 10 2 Sevens are 14 2 Thirteens are 26 3 Fives are 15 3 Sevens are 21 3 Thirteens are 39 4 Fives are 20 4 Sevens are 28 4 Thirteens are 52 5 Fives are 25 5 Sevens are 35 5 Thirteens are 65

17) PROGRAM ON EXCEPTION HANDLING class error public static void main (String args[]) int a[]=5,10; int b=5; try int x= a[2]/b-a[1]; catch(arithmeticexception e) System.out.println("Division by zero"); catch(arrayindexoutofboundsexception e) System.out.println("Array index error"); catch(arraystoreexception e) System.out.println("Wrong Data type"); int y=a[1]/a[0]; System.out.println("y="+y); Out put Array index error y=2

18) PROGRAM FOR DRAWING HUMAN FACE USING GRAPHICS import java.awt.*; import java.applet.*; /*<APPLET CODE=Face.class WIDTH=250 HEIGHT=200> </APPLET>*/ public class Face extends Applet public void paint(graphics g) g.drawoval(40,40,120,150); g.drawoval(57,75,30,20); g.drawoval(110,75,30,20); g.filloval(68,81,10,10); g.filloval(121,81,10,10); g.drawoval(85,100,30,30); g.fillarc(60,125,80,40,180,180); g.drawoval(25,92,15,30); g.drawoval(160,92,15,30); Output

19) PROGRAM TO OBTAIN SUM OF TWO NUMBERS USING APPLET import java.awt.*; import java.applet.*; /*<APPLET CODE=UserIn.class WIDTH=250 HEIGHT=200> </APPLET>*/ public class UserIn extends Applet TextField text1,text2; public void init() text1 = new TextField(8); text2 = new TextField(8); add(text1); add(text2); text1.settext("0"); text2.settext("0"); public void paint (Graphics g) int x=0, y=0,z=0; String s1,s2,s; g.drawstring("input a number in each box ",10,50); try s1 = text1.gettext(); x=integer.parseint(s1); s2=text2.gettext(); y=integer.parseint(s2); catch(exception ex) z=x+y; s= String.valueOf(z); g.drawstring(" THE SUM IS: ", 10,75); g.drawstring(s,100,75);

public boolean action( Event event, Object obj) repaint(); return true; OUT PUT

20) PROGRAM TO SHOW CROSS LINES USING GRAPHICS APPLET import java.applet.*; import java.awt.*; /*<APPLET CODE = "Crossed.class" WIDTH = 600 HEIGHT = 600> </APPLET>*/ public class Crossed extends Applet public boolean handleevent( Event e) if(e.id == Event.WINDOW_DESTROY) System.exit(0); return(super.handleevent(e)); public void paint(graphics g) for(int i=0;i<400;i+= 10) g.drawline(0,i,i,0); g.drawline(i,400,400,i); for(int j=0,k=400;j<400;j+= 10,k -=10) g.drawline(0,k,400,j); g.drawline(0,j,k,400);

Out put of Crossed lines