Skip to main content

Posts

Showing posts from May 22, 2014

solve quadratic equation in java

import java.io.*; class Root { public static void main(String args[])throws IOException {  int a,b,c;  double d,x,y; DataInputStream in = new DataInputStream(System.in); System.out.println("Enter the value of a,b,c"); a=Integer.parseInt(in.readLine()); b=Integer.parseInt(in.readLine()); c=Integer.parseInt(in.readLine()); d=b*b-4*a*c; if(d>=0) { if(d==0) { x=-b/(2*a); y=-b/(2*a); System.out.println("roots are real and equal,so the number is perfect square"); } else { System.out.println("roots are real and distinct"); } } else { System.out.println("roots are imaginary"); } } } class square { public void root1(int x,int y,int z ) { a=x; b=y; c=z; r1=((-b)+(Math.sqrt(d)))/(2*a); r2=((-b)-(Math.sqrt(d)))/(2*a); System.out.println("first root is"+r1); System.out.println("second root is"+r2); }

program to count spaces in a string

import java.io.*; class Space { static String s;   int l=s.length();   int n=0;   int i;   public int lack(String x)   {   String c;   c=x;   for(i=0;i<l;i++)   {   char ch=c.charAt(i);   if(ch==' ')   {   n++;   }   }   return n;   } public static void main(String args[]) throws IOException { DataInputString z=new DataInputString(System.in); String x; System.out.println(enter string"); x=z.readLine(); Space m= new Space(); int l=m.lack(s); System.out.println("number of spaces are" +l); } }

program for extracting vowel from sentence using array

//program for extracting vowel from sentence using array import java.io.*; class vl1 {   public static void main(String args[])throws IOException  {   DataInputStream in = new DataInputStream(System.in);   System.out.println("enter the sentence");   String s=in.readLine();//stores the entered string in s   String tmp="",h="";   s=s.trim();   String g=s.toLowerCase();   g=g+" ";   int count=0,p=0,i;   int l=g.length();  try {//for counting no.of spaces in the string entered  for( i=0;i<l;i++)    {      char ch=g.charAt(i);      if(ch==' ') count+=1;    } String d[]=new String[count];//array declaration with size for(i=0;i<l;i++) {   char ch=g.charAt(i);      if(ch!=' ') tmp=tmp+ch; else { d[p]=tmp; p+=1; tmp=""; } } int j; //for printing vowels from the sentences for( i=0;i<count;i++) { String m=d[i]; h="";   for(j=0;j<m.length();j++) {      char x

First GUI application using advance Java

import javax.swing.*; import javax.swing.event.*; import java.awt.*; import java.awt.event.*; class layout implements ActionListener {   JFrame jframe;   JButton jbutton;   JTextField jtf1;   JTextField jtf2;   layout()   {   GUI();   action();   jframe.setVisible(true);   }   void GUI()   {   jframe=new JFrame("My Layout");   jframe.setSize(500,500);   jframe.setDefaultCloseOperation(jframe.EXIT_ON_CLOSE);   jbutton=new JButton("Check");   jtf1=new JTextField("enter string here");   jtf2=new JTextField();   jframe.add(jbutton,BorderLayout.CENTER);   jframe.add(jtf1,BorderLayout.NORTH);   jframe.add(jtf2,BorderLayout.SOUTH);   }   void action()   {   jbutton.addActionListener(this);   } public void actionPerformed(ActionEvent ae)   {   if(ae.getActionCommand().equals("Check"))   {     String mk=jtf1.getText(); mk=' '+mk; char ch=' '; String str=""; int l=mk.lastIndexOf('

Swing Example

import java.applet.*; import javax.swing.*; import javax.swing.event.*; import java.awt.event.*; import java.awt.*; import java.io.*; import java.lang.*; interface Stringf { public void concat(String p); public void pallin(String p); public void count(String p); } class Test1 implements ActionListener, Stringf { JFrame jframe; JToolBar jtb; JButton b; //JButtonb2; JTextField jtf,jtf2; JList jl; int l,i,j; String p2; String ar[]={"pallindrome","count","concat"};  Test1() { initGUI(); initJEvents(); jframe.setVisible(true); } int check(String t) { l=t.length(); if(l>0) return(1); return(0); } public void pallin(String p) { p2=""; if(check(p) ==1) { for(i=0;i<l;i++) p2=p.charAt(i)+p2; } jtf2.setText(p2); } public void concat(String p) { p2=""; if(check(p)==1) { for(i=0;i<l;i++) if(p.charAt(i) !='#') p2=p2+p.charAt(i); } jtf2.setText(p2); } public voi

Got approved by adsense

some tips are: Get a Seo Optimised template Write atleast 100 posts.