Java Java

  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Java Java as PDF for free.

More details

  • Words: 719
  • Pages: 2
temp class temp{public float temp1(float c){float f;f=(c+32)*9/5;return f;}}class temperature{public static void main(String args[]){temp t=new temp();float t1=t.temp1(25); System.out.println("the value of temp in fahrenite is"+t1);}} class fibbon{public void fibbo1(int s,int n){int c=0;System.out.println("the fibonacci series is:");System.out.println(s);do{ c=c+1;s=s+n; System.out.println("/t"+s); n=s-n;}while(c!=10);}}class fibbo{public static void main(String args[]){fibbon f=new fibbon();f.fibbo1(0,1);}} class fact{long i,s=1;long factorial(int n){for(i=n;i!=0;i--){s=s*i;}return s;}}class facto{public static void main(String args[]){fact f=new fact();long f1=f.factorial(3);System.out.println("the factorial is:"+ f1);}} class SumofDigit {int i,a,b,c,d,e,f,g,h,j; int SumDigit(int i) { a=i/10000; b=i%10000; c=b/1000; d=b%1000; e=d/100; f=d%100; g=f/10; h=f%10; j=a+c+e+g+h; return j;}}public class DigitSum{public static void main(String args[]){ SumofDigit obj=new SumofDigit();int fact=obj.SumDigit(654); System.out.println("the sum of digits of numbers is"+fact);}} class comlintest{public static void main(String args[]){int count,i=0;String string;count=args.length; System.out.println("no. ofarguments="+count);while(i0){ rem=(n%10)+(rem*10); n=n/10; }System.out.println("the reverse of a number:"+rem);} catch(Exception e){System.out.println(e);} class PatternDisplayTest{public static void main(String args[]){intc=0,r;for(r=1;r<10;r++){for(c=1;c<=r;c++){System.out.print(r); }System.out.println();}}} class testrnumber[]={50,65,56,71,81};int even=0,odd=0;for(inti=0;i=80 && avg<100) System.out.println("honors");else if(avg>=60 && avg<=79)System.out.println("you have I div")else if(avg>=50 && avg<=59) System.out.println("you have II div"); else if(avg>=40 && avg<=49) System.out.println("you have III div");else if(avg>=0 && avg<=39) System.out.println("you are fail");}} public class CityMenu{ public static void main(String a[] { char choice; try { System.out.println("Choose ur city:");System.out.println("M=Mumbai");System.out.println("C=Chennai");System.out.println("D=Delhi");System.out.println("N=Nagpur";switch(choice=(char)System.in.read()) { case 'M': System.out.println("your city is Mumbai, whose population is 10 crore.") break; case 'C': System.out.println("your city is Chennai, whose population is 3 crore."); break; case 'D': System.out.println("your city is Delhi, whose population is 5 crore."; break; case 'N': System.out.println("your city is Nagpur, whose population is 1 crore."); break; default: System.out.println("invalid choice"); break; } } catch(Exception e){ }}} import java.io.*;public class TableTest { public static void main(String args[]) { int i,j=1,n; try{BufferedReader br =newBufferedReader(newInputStreamReader(System.in)); System.out.println("Enter the number whose table you want"); n=Integer.parseInt(br.readLine()); for(i=1;i<=n;i++) { System.out.println("The Table of "+i); do { System.out.println(i +" * "+j+" = "+ (i*j)); j++; }while(j<=10); j=1; } } catch(Exception e) { System.out.println(e); }}} public class SortOrder { public static void main(String args[]) { int[] a={5,9,2,8,3}; int i,j,t; for(i=0;i<4;i++) { for(j=i+1;j<5;j++) { if (a[i]>a[j]) { t=a[i]; a[i]=a[j]; a[j]=t; }}} System.out.println("The sorted numbers are:\n"); for(i=0;i<5;i++) System.out.println(a[i]);} } public class SortString { static String strArr[]={"now","we","are","planning","to","do","java","program"};public static void main(String args[]){ for(int j=0;j<strArr.length;j++) { for(int i=j+1;i<strArr.length;i++) { if(strArr[i].compareTo(strArr[j])<0) { String t=strArr[j];strArr[j]=strArr[i];strArr[i]=t;}}System.out.println(strArr[j]);}}} public class StringMethodTest{ protected StringMethodTest() { } public static void main(final String[] args) { String string1,string2,string3,string4; string1=new String("Answer"); string2=new String("ANSWER"); string3=new String("Java is a platform independent language"); string4=new String(" Hello World "); System.out.println("String A is "+ string1); System.out.println("String B is "+string2); if(string1.equals(string2)) { System.out.println("String A and String B have same content"); } else { System.out.println("String A and String B have different content"); } if(string1.compareTo("Answer")==0) { System.out.println("String A have same content alphabetically as Answer"); } else{ System.out.println("String A have different content alphabetically from Answer");} System.out.println("String C is "+string3); System.out.println("index oft="+string3.indexOf('t'));System.out.println("Substring of String 3 is: "+string3.substring(6)); System.out.println("Another Substring of String 3 is: "+string3.substring(3,8)); System.out.println("Concatenation with String 3 is: "+string3.concat(" The feature Of Java")); System.out.println("Replacement in String 3 is: "+string3.replace('p', 'f')); System.out.println(" String 4 is: "+ string4); System.out.println(" String 4 trimmed as: "+string4.trim());}} Import java.awt.*;import java.applet.*;public class HelloJavaParam extends Applet{ String str; public void init() { str= getParameter("string"); if(str==null) str="Java"; str="Hello "+str; } public void paint(Graphics g) { g.drawString(str, 10, 100); }} .htmlfileWelcome<param name="string" value="Applet"> import java.awt.*;import java.applet.*;public class Face extends Applet { public void paint(Graphics g) { g.setColor(Color.PINK); g.drawOval(40, 40, 120, 150);//HEAD g.fillOval(40, 40, 120, 150); g.setColor(Color.MAGENTA); g.drawOval(57, 75, 30, 20);//Left Eye g.drawOval(110,75,30,20);//Right Eye g.fillOval(68,81,10,10); //Pupil Left eye g.fillOval(121, 81, 10, 10);//Pupil Right eye g.drawOval(85, 100, 30, 30);//Nose g.fillArc(60, 125, 80, 40, 180, 180);//Mouth g.drawOval(25, 92, 15, 30);//Left Ear g.drawOval(160,92, 15,30);//Right ear}} Welcome<param name="string" value="Applet"> import java.awt.*;public class DemoBorder extends Frame{Button bnorth = new Button("North");Button bwest = new Button("West");Button bsouth = new Button("South");Button beast = new Button("East");Button bcenter = new Button("Center");public DemoBorder() { setLayout(new BorderLayout());add(bnorth,BorderLayout.NORTH);add(bwest ,BorderLayout.WEST);add(bsouth,BorderLayout.SOUTH);add(beast,BorderLayout.EAST);add(bcenter,BorderLayout.CENTER);setBackground(Color.gray); setTitle("BorderLayoutDemo");setResizable(true);setSize(250,250);setVisible(true);} public staticvoidmain(Stringargs[]){newDemoBorder();}} import java.awt.*;import java.awt.event.*;public class ButtonDemo extends Frame implements ActionListener{Button bRed;Button bBlue;Button bGreen;Button bYellow;Button bPink; publicButtonDemo(){setLayout(null);bRednewButton("RED");bBlue=newButton("BLUE");bGreen=newButton("GREEN");bYellow=newButton("YELLOW");b Pink=newButton("PINK");add(bRed);add(bBlue);add(bGreen);add(bYellow);add(bPink);bRed.setBounds(25,50,60,30);bBlue.setBounds(25,100,60,30);bGre en.setBounds(25,150,60,30);bYellow.setBounds(25,200,60,30);bPink.setBounds(25,250,60,30);bRed.addActionListener(this);bBlue.addActionListener(thi s);bGreen.addActionListener(this);bYellow.addActionListener(this);bPink.addActionListener(this);setTitle("ClickbuttontoviewColor");setSize(300,300);s etVisible(true);}publicvoidactionPerformed(ActionEventae){if(ae.getSource()==bRed){setBackground(Color.red);}elseif(ae.getSource()==bBlue){setBackg round(Color.blue);}elseif(ae.getSource()==bGreen){setBackground(Color.green);}elseif(ae.getSource()==bYellow){setBackground(Color.yellow);}else{set Background(Color.pink);}} publicstaticvoidmain(Stringarg[]){newButtonDemo();}}OUTPUT:=>C:\jdk1.5.0\bin>javacButtonDemo.javaC:\jdk1.5.0\bin>javaButtonDemo Password importjava.awt.*;importjava.awt.event.*;importjava.applet.*;publicclassAdminextendsFrameimplementsActionListener{TextField t1, t2;Button b1,b2;String msg= "";Label l1, l2;Font f; public Admin(){setLayout(null);t1= new TextField("");t2= new TextField("");b1= new Button("Fine");b2=newButton("Cancle");l1=newLabel("UserName");l2=newLabel("Passward");t2.setEchoChar('*');f=new Font("Arial",Font.ITALIC,15);l1.setBounds(25,40,80,25);t1.setBounds(125,40,80,25);l2.setBounds(25,80,80,25);t2.setBounds(125,80,80,25);b1.setBounds( 45,140,60,25);b2.setBounds(125,140,80,25);b1.setFont(f);b2.setFont(f);add(l1);add(t1);add(l2);add(t2);add(b1); add(b2);b1.addActionListener(this);b2.addActionListener(this);setTitle("Welcome");setBackground(Color.gray);setSize(250,250);setVisible(true);setResi zable(false);addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent we){System.exit(0);}});}public void actionPerformed(ActionEvent ae){if(ae.getSource()==b1){if(t1.getText().equals("Admin")){ if(t2.getText().equals("system")){msg="LoginSuccessfully";}elsemsg="LoginFailed";}else{msg="Tryagain!!!!";}}else{System.exit(0);}repaint();} public void paint(Graphics g){g.drawString(msg,100,200);g.setColor(Color.red);g.setFont(f); } public static void main(String arg[]){new Admin();}}OUTPUT:=>C:\JDK15~1.0\bin>javacAdmin.javaC:\JDK15~1.0\bin>java Admin Checkbox import java.awt.*;import java.awt.event.*;public class CBGEvent extends Frame implements ItemListener{Labell1;CheckboxchkPlay,chkNet,chkRead,chkWrite;CheckboxGroupcbg;Stringmsg="";publicCBGEvent(){setLayout(newFlowLayout(FlowL ayout.LEFT));l1=newLabel("TickoneofyourHobby");cbg=newCheckboxGroup();chkPlay=newCheckbox("Playing",cbg,true);chkNet=newCheckbox("NetSur fing",cbg,true);chkRead=newCheckbox("Reading",cbg,true);chkWrite=newCheckbox("Writing",cbg,true);add(l1);add(chkPlay);add(chkNet);add(chkRead) ;add(chkWrite);chkPlay.addItemListener(this);chkNet.addItemListener(this);chkRead.addItemListener(this);chkWrite.addItemListener(this);l1.setBckgro und(newColor(223,153,123));setTitle("Hobbies");setSize(200,200);setBackground(Color.pink);setVisible(true);}publicvoiditemStateChanged(ItemEventie) {msg="YourHobbyis:";msg+=cbg.getSelectedCheckbox().getLabel();repaint();}publicoidpaint(Graphicsg){g.drawString(msg,20,150);g.setColor(Color.red); }public static void main(String args[]){newCBGEvent();}}OUTPUT:=>C:\JDK15~1.0\bin>javac CBGEvent.javaC:\JDK15~1.0\bin>java CBGEvent importjava.awt.*;publicclassListDemoextendsFrame{Labell1=newLabel("ClickurOption");publicListDemo(){Listdish,toppings;LabellCity,lSub;setLayout(n ewGridLayout(2,2));lCity=newLabel("SelectyourfavoDish");lSub=newLabel("SelectyourfavoToppings");dish=newList(1,false);toppings=newList(1,true);dis

h.add("Pizza");dish.add("Burger");dish.add("Noodles");dish.add("Sizzler");dish.add("Cutlets");toppings.add("Cheese");toppings.add("Paneer");toppings.a dd("Corn");toppings.add("Vegetable");toppings.add("Mushrooms");add(lCity);add(dish);add(lSub);add(toppings);setBackground(newColor(175,162,105)); setTitle("DemoofListBox");setSize(280,185);setVisible(true);}publicstaticvoidmain(Stringarg[]){newListDemo();}}OUTPUT:=>C:\JDK15~1.0\bin>javacListDe mo.javaC:\JDK15~1.0\bin>java ListDemo

Related Documents

Java Java
June 2020 44
Java
November 2019 24
Java
November 2019 26
Java
December 2019 27
Java
November 2019 23
Java
November 2019 25