Sei sulla pagina 1di 20

Laxmi Devi Institute of Engineering & Technology, Alwar Rajasthan Technical University, Kota

A JAVA PROGRAM FILE 2009-10 Session

Submitted to -

Submitted by -

Mr.Paranay mishra ( Assistant prof.) LIET Alwar

Name : Tarun Khandelwal Roll No. : 08ELDEE059 Sem : 4th sem

S.NO

NAME OF PROGRAM

DATE

SIGN

REMARK

A PROGRAM WITH MULTIPLE STATEMENTS

PROGRAM -

/* * More Java Statements * This Code Computes Squre root */ Import java.lang.math; Class squreroot { Public static void main(String args[] ) { Double x=5; Double y; y = Math.sqrt(x); System.out.println(y=+y); } }

OUTPUT: y=2.23607

A PROGRAM WITH MULTIPLE CLASSES

PROGRAM -

Class room { Float length; Float breath; Void getdata(float a, float b) { Length =a; Breath=b; } } Class RoomArea { Public static void main (String args[]) { Float area; Room room1=new room(); Room1.getdata(14,10); Area=room1.length*room1.breath; System.out.println(Area=+area); }

OUTPUT: -

140

A PROGRAM USING COMMANDLINE ARGUMENT

PROGRAM -

/* * This Program Uses Command Line * Arguments As Input; */ Class ComlineTest { Public static void main(String arga[]) { 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+ :); } } }

OUTPUT:-

Number of arguments+5 1: Java is simple! 2: Java is object oriented! 3: Java is distributed! 4: Java is robust! 5: Java is portable!

PROGRAM

Import java.i.o*; Class jps { Public static void main (string args []) { String snum; Int num1, num2; Try { DataInputStream input; input = new DataInputStream (system.in); System.out.println(Enter first number); snum = input.readline( ); num1 = integer.parseInt(snum); System.out.println(enter second number); snum = input.readline( ); num2 = integer.parseInt(snum); int num3 = num1+num2; System.out.println(sum+num3); } Catch(Exception eobj) { System.out.println(Error); } }

OUTPUT:Enter first number 10 Enter second number 20 Sum 30

mport java.i.o*; Class JSP { Public static void main (string agrs[]) { String snum; int a, b,c,max1,max; try { DataInputStream input; input = new DataInputStream(system.in); system.out.println(Enter first number); a = Integer.parseInt(input.readline( )); system.out.println(Enter second number); b = Integer.parseInt(input.readline( )); system.out.println(Enter third number); c = Integer.parseInt(input.readline( )); max1 = a>b? a:b; max1>c?max1:c; system.out.println(a= +a); system.out.println(b= +b); system.out.println(c= +c); system.out.println(Maximum= +max); } Catch(Exception eobj) { System.out.print(Error); } } }

OUTPUT: Enter first number 12 Enter second number 40 Enter third number 25 a = 12 b = 40 c = 25 Maximum = 40

A PROGRAM WITH GROSS SALARY OF THE PERSON PROGRAM Import java.io.* Class JPS { Public static void main(string args[]) { Float bs,gs,hra,da; try { DataInputStream input = new DataInputStream(system.in); System.out.println(Enter your basic salary); bs = float.valueof(input.readline( )).floatvalue( ); if (bs<=5000) { da = (bs*45)/100; hra = (bs*15)/100; } else { da = (bs*55)/100; hra = (bs*15)/100; } gs = bs + da + hra ; system.out.println(Basic salary is +bs); system.out.println(HRA is+hra); system.out.println(DA is+da); system.out.println(Gross salary is +gs); } Catch(Exception eobj) { System.out.println(Error); } } }

OUTPUT: Enter your basic salary 12000 Basic salary is 12000.0 HRA is 1800.0 DA is 6600.0 Gross salary is 20400.0

A PROGRAM WITH SORTIG A LIST OF NUMBERS PROGRAM -

Class NumberSorting { Public static void main (string args []) { int number [] = { 55, 40, 80, 65, 71}; int n = number.length; System.out.print(Give list :); for (int i= 0; i < n; i++); { System.out.print( + number*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.print( Sorted list : ); for (int i = 0; i < n; i++) { System.out.print( + number,i-); } System.out.println( ); } }

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

A PROGRAM WITH CHECK A CHARACTER FOR VOWEL

PROGRAM Import java.io.*; Class Temp { Public static void main(string args[]) { Char ch; try { DataInputStream input; input = new DataInputStream(system.in); system.out.println(Enter any character); ch = (char)inpu.read( ); switch(ch) { Default: Break; Case a: Case e: Case i: Case o: Case u: System.out.println(It is vowel); Break; } } Catch(Exception eobj) { System.out.println(Error); } } }

OUTPUT: Enter any number a it is a vowel.

A PROGRAM WITH IMPLEMENTING INTERFACE PROGRAM Interface Area { final static float pi = 3.14f; float compute (float x, float y); } Class Rectangle implements Area { Public float compute (float x, float y) { return (x * y); } } Class Circle implements Area { Public float compute (float x, float y) { return (pi * x *x); } } Class Interface Test { Public static void main (String args []) { Rectangle rect = new Rectangle ( ); Circle cir = new Circle ( ); Area area; area = rect; System.out.println (Area of Rectangle = + area.compute (10, 20)); area = cir; System.out.println (Area of Circle = + area. compute (10, 0)); } }

OUTPUT:Area of rectangle = 200 Area of circle = 314

A PROGAM WITH SINGLE INHERITANCE PROGRAM Class Room { int length; int breadth; Room (int x, int y) { length=x; breath=y; } int area( ) { return (length * breath); } } Class Bedroom extends Room { int height; BedRoom (int x, int y, int z) { Super (x, y) height = z; } int volume( ) { return (length * breadth * height); } Classs InherTest { Public static void main ( String args[] ) { BadRoom room1 = new Badroom(14,12,10); int area1 = room1.area( ); int volume1 = room1.volume( ); System.out.println(Area1= +area1 ); System.out.println(volume= +volume); } }

OUTPUT:Area1 = 168 Volume = 1680

PROGRAM -

import java.util.calender; Class temp { Public satic void main(string args []) { Calendar cal = calendar.getInstance ( ); int h = cal.get (calendar.HOUR); int m = cal.get (calendar.MINUTE); int s = cal.get (calendar.SECOND); System.out.println(Time is +h :+m : +s); int day = cal.get (calendar.DAY_OF_MONTH); int mon = cal.get (calendar.MONTH); mon++; int yr = cal.get (calendar.YEAR); System.out.println(Date is + day + / + mon + / + yr); } }

OUTPUT: Time is 10:40:43 Date is 15/04/2008

PROGRAM Import java.awt.*; Import java.applet.*; Import java.awt.event.*; Public class button extends applet Implements Actionlistioner { Button but; String disp = ; Public void init ( ) { but = new Button (click me); add(but); but.addActionlistener(this); } Public void actionperformed(ActionEvent, AE) { disp = you clicked me; repaint ( ); } Public void paint (Graphics g) { g.drawstring(disp,80,100); } } // html file <html> <applet code= button width = 200*height = 150> </applet> </html>

OUTPUT: Applet viewer : button[][] Applet:

Click me

You clicked me

Applet started

A PROGRAM OF APPLET SHARING TEXTFIELD

PROGRAM Import java.awt.*; Import java.applet.*; import java.awt.event.*; public class button1 extends Applet implements Actionlistner { Button butt; String text = ; Boolean in = false; int h,w; Textfield tf; Llabel l; Public void init( ) { SetBackground(color.pink); L = new Label (Please enter your name); tf = new TextField (30); but1 = new Button (click Me Now); add(L); add(tf); add(but1); but1.addActionListener(this); } Public void actionPerformed (ActionEvent AE) { if(AE.getsource( )= but1) { Text = hello + tf.getText( ); Repaint( ); } } Public void paint(Graphics g) { g.setcolor(color.blue); g.drawstring(text,120,125); } } //html file <html> <applet code = button3 width=300 height = 150>

</applet> </html>

OUTPUT: Applet viewer button3 Applet Please enter your name LIETANS Click Me Now Hello LIETANS Applet Started

UNIX COMMANDS
ls ................. show directory, in alphabetical order logout ............. logs off system mkdir .............. make a directory rmdir .............. remove directory (rm -r to delete folders with files) rm ................. remove files cd ................. change current directory man (command) ...... shows help on a specific command talk (user) ........ pages user for chat - (user) is a email address write (user) ....... write a user on the local system (control-c to end) pico (filename) .... easy to use text editor to edit files pine ............... easy to use mailer more (file) ........ views a file, pausing every screenful sz ................. send a file (to you) using zmodem rz ................. recieve a file (to the unix system) using zmodem telnet (host) ...... connect to another Internet site ftp (host) ......... connects to a FTP site archie (filename) .. search the Archie database for a file on a FTP site irc ................ connect to Internet Relay Chat lynx ............... a textual World Wide Web browser gopher ............. a Gopher database browser tin, trn ........... read Usenet newsgroups passwd ............. change your password chfn ............... change your "Real Name" as seen on finger chsh ............... change the shell you log into grep ............... search for a string in a file tail ............... show the last few lines of a file who ................ shows who is logged into the local system

w .................. shows who is logged on and what they're doing finger (emailaddr).. shows more information about a user df ................. shows disk space available on the system du ................. shows how much disk space is being used up by folders chmod .............. changes permissions on a file bc................. a simple calculato make ............... compiles source code gcc (file.c) ....... compiles C source into a file named 'a.out'

Potrebbero piacerti anche