Date: 16-12-2008 Week-1a) Aim : Write a java program that print all roots of equation of quadratic a,b,c will be supplied through keyboard Code: import java.lang.*; import java.math.*; class Quad { public static void main(String arg[]) { int a,b,c; a=Integer.parseInt(arg[0]); b=Integer.parseInt(arg[1]); c=Integer.parseInt(arg[2]); int delta=(b*b)-(4*a*c); if(delta<0) { System.out.println("roots are imaginary,no real values"); } else { double x1=(-b+Math.sqrt(delta))/(2*a); double x2=(-b-Math.sqrt(delta))/(2*a); System.out.println(x1+" "+x2); } } } Output: WWW.ABHIROX.CO.CC , WWW.ABHIROX.CO.NR
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Date: 16-12-2008Week-1a)Aim : Write a java program that print all roots of equation of quadratic a,b,c will be supplied through keyboardCode:import java.lang.*;import java.math.*;class Quad{ public static void main(String arg[])
{ int a,b,c; a=Integer.parseInt(arg[0]);
b=Integer.parseInt(arg[1]); c=Integer.parseInt(arg[2]); int delta=(b*b)-(4*a*c);
if(delta<0) { System.out.println("roots are imaginary,no real values");
Week-1b)Aim : Write a java program that uses both recursive and non recursive functions to print the nth value in Fibonacci series.Code:import java.lang.*;class Fibo{
public static void main(String arg[ ]){
int f,f1=0,f2=1,n;n=Integer.parseInt(arg [0]);System.out.println(f1);System.out.println(f2);for(int i=0;i<n-1;i++){
f=f1+f2;f1=f2;f2=f;System.out.println(f);
}System.out.println("Fibonacci series using recursion");for(int i=0;i<n;i++)
Date: 23-12-2008Week-2a)Aim: Write a java program that prompts the user for an integer and then prints out all prime numbers upto the integer.Code:import java.lang.*;class Prime {
public static void main(String arg[]){
int n,c,i,j;n=Integer.parseInt(arg[0]);System.out.println("prime numbers are");for(i=1;i<=n;i++){
Week-2b)Aim: Write a java program to multiply two given matrices.Code:import java.lang.*;import java.io.*;class Matrix{
public static void main(String arg[])throws IOException{
DataInputStream dis=new DataInputStream(System.in);System.out.println("Enter The Row Size Of The First Matrix");int r1=Integer.parseInt(dis.readLine());System.out.println("Enter The Column Size Of The First Matrix");int c1=Integer.parseInt(dis.readLine());System.out.println("Enter The Row Size Of The Second Matrix");int r2=Integer.parseInt(dis.readLine());System.out.println("Enter The Column Size Of The Second Matrix");int c2=Integer.parseInt(dis.readLine());int a[][]=new int[r1][c1];int b[][]=new int[r2][c2];int c[][]=new int[r1][c2];int i,j,k;System.out.println("Enter The Elements Into The First Matrix");for(i=0;i<r1;i++)for(j=0;j<c1;j++){
a[i][j]=Integer.parseInt(dis.readLine());}System.out.println("Enter The Elements Into The Second Matrix");for(i=0;i<r2;i++)for(j=0;j<c2;j++){
b[i][j]=Integer.parseInt(dis.readLine());}if(c1!=r2)System.out.println("Multiplication Is Not Possible");else{
Date: 30-12-2008Week-3a)Aim: Write a java program that checks whether a given string is a palindrome or not.Ex:MADAMCode:import java.lang.*;import java.io.*;import java.util.*;class Palindrome{
public static void main(String arg[ ]) throws IOException{
Week-3b)Aim:Write a java program for sorting a given list of name in ascending order.Code:import java.lang.*;import java.io.*;import java.util.*;class Sort{
public static void main(String arg[ ]) throws IOException{
Week-3c)Aim: Write a java program to make frequency count of words in a given text.Code:import java.util.*;import java.lang.*;import java.io.*;class Fre{
public static void main(String[ ] args) throws IOException{
Date: 06-01-2009Week-4a)Aim: Write a java program that reads a filename from user then displays information from user then displays information about whether the file exists,whether file is readable, whether file is writable the type of file and length of file in bytes.Code:import java.lang.*;import java.io.*;import java.util.*;class FileOp{ public static void main(String arg[ ])throws IOException
Week-4b)Aim: Write a java program that reads a file and displays the file on the screen with a line number before each line.Code:import java.util.*;import java.io.*;import java.lang.*;class FileNo{
public static void main(String arg[ ])throws IOException{
Week-4c)Aim: Write a java program that displays the number of characters,lines and words in atext fileimport java.lang.*;import java.io.*;class FileCount{
System.out.println("line count is "+lcount);System.out.println("Character count is "+ccount);System.out.println("word count is "+wcount);
}catch(Exception e){
System.out.println(e);}
}}Output:
Date:03-02-2009Week-5a)i)Aim: Write a java program that Implements stack ADT.Code:import java.lang.*;import java.io.*;import java.util.*;interface Mystack{ int n=10; public void pop(); public void push(); public void peek(); public void display();} class Stackimp implements Mystack{
Week-5a)ii)Aim: Write a java program that evaluates the postfix expression Code:import java.lang.*;import java.io.*;import java.util.*;class IntoPo{ public static void main(String arg[])throws IOException { Stack stk=new Stack();
case '0' : case '1' : case '2' : case '3' : case '4' : case '5' : case '6' : case '7' : case '8' : case '9' : stk.push(new Integer((Character.digit(ch,10)))); break; case '+': case '-': case '/': case '*':
Date: 10-02-2009Week-6a)Aim:Develop an applet that receives an integer in one text field, and computes as factorial value and returns it in another text field,when the button named “Compute” is clicked
l=new Label("Enter the number & press the button");tf1=new TextField("",5);tf2=new TextField("",10);b=new Button("press me");add(l);add(tf1);add(tf2);add(b);b.addActionListener(this);
Aim: Write a java program that works as a simple calculator.Use a grid layout to arrange buttons for the digits +,-,*,/,% operations.Adda text field to display the result.import java.awt.*;import java.applet.*;import java.awt.event.*;public class Calculator extends Applet implements ActionListener{
Week-9a)Aim: Write a java program that creates three threads.First thread displays”Good Morning” every one second,the second thread displays “Hello” every two seconds and the third thread displays “Welcome” every three seconds.Code:class Frst implements Runnable{ Thread t; Frst() { t=new Thread(this); System.out.println("Good Morning"); t.start(); }
Aim: Write a java program that correctly implements producer consumer problem using the concept of inter thread communication.Code:import java.lang.*;import java.lang.Thread;class Q {
int n;boolean valueSet=false;synchronized int get(){
Week-10 )Aim: Write a program that creates a user interface to perform integer divisions.The user enters two numbers int the textfields,Num1 and Num2.The divison of Num1 and Num2 is displayed in the Result field when the Divide button is clicked.If Num1 or Num2 were not an integer,the program would throw a NumberFormatException.If Num2 were Zero,the program would throw an ArithmeticException Display the exception in a message dialog box.Code:import java.awt.*;import java.awt.event.*;import java.applet.Applet;import javax.swing.*;/*<applet code="AddEvent.class" height=100 width=500></applet>*/public class AddEvent extends Applet implements ActionListener{
Aim: Write a java program that implements a simple client/server application. The client sends a data to a server. The server receives the data uses it to produce a result, and then sends the result back to the client. The client displays the result on the console .For Ex: The data sent from the client is the radius of a circle ,and the result produced by the server is the area of the circle,(Use java.net)Code:import java.io.*;import java.net.*;class Client {
public static void main(String ar[])throws Exception{
Socket s=new Socket(InetAddress.getLocalHost(),10000);System.out.println("enter the radius of the circle ");DataInputStream dis=new DataInputStream(System.in);int n=Integer.parseInt(dis.readLine());PrintStream ps=new PrintStream(s.getOutputStream());ps.println(n);DataInputStream dis1=new DataInputStream(s.getInputStream());System.out.println("area of the circle from server:"+dis1.readLine());
}}
import java.io.*;import java.net.*;class Server{
public static void main(String ar[])throws Exception{
Aim: Write a java program that stimulates a traffic light. The program lets the user select one of three lights: red, yellow, or green. When a radio button is selected, the light is turned on, and only one light can be on at a time No light is on when the program starts.Code:import java.awt.*;import java.awt.event.*;import java.applet.*;/*<applet code="CBGroup" width=250 height=200></applet>*/public class CBGroup extends Applet implements ItemListener{
Aim: Write a java program that allows the user to draw lines,rectangles and ovals.Code:import java.awt.*;import java.applet.*;public class Draw extends Applet{
Week-13a)Aim: Write a java program to create an abstract class named Shape that contains an empty method name numberOfSides().Provide three classes named Trapezoid,Traingle and Hexagon such that each of the classes extends the class Shape. Each one of the classes contains only the method numberOfSides() that shows the number of sides in the given geometrical figures.Code:import java.lang.*;abstract class Shape{ abstract void numberOfSides();
Week-13b)Aim: Suppose that a table named Table.txt is stored in a text file. The first line in the file is the header, and the remaining lines corresponding to rows in the table. The elements are separated by commas. Write a java program to display the tabe using JTable Component.Code:import javax.swing.*;import java.awt.*;import java.io.*;import java.util.*;public class JTableEx extends JPanel{
public JTableEx() {
super(new GridLayout(1, 0));File file = new File("I:/Table.txt");FileInputStream fis = null;BufferedInputStream bis = null;DataInputStream dis = null;String initData[] = new String[100];String[] columnNames = null;Object[][] data = null;int rows = 0;try{
fis = new FileInputStream(file);bis = new BufferedInputStream(fis);dis = new DataInputStream(bis);while (dis.available() != 0){
initData[rows++] = dis.readLine();}StringTokenizer st = new StringTokenizer(initData[0],",");columnNames = new String[st.countTokens()];data = new Object[rows - 1][st.countTokens()];for (int i = 0; i < rows; i++){
if (i != 0){
int k = 0;StringTokenizer st1 = new StringTokenizer(initData[i],",");while (st1.hasMoreTokens()){
e.printStackTrace();}final JTable table = new JTable(data, columnNames);table.setPreferredScrollableViewportSize(new Dimension(500, 100));//table.setFillsViewportHeight(true);JScrollPane scrollPane = new JScrollPane(table);add(scrollPane);
}
private static void createAndShowGUI(){
JFrame frame = new JFrame("SimpleTableDemo");frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);JTableEx newContentPane = new JTableEx();newContentPane.setOpaque(true);frame.setContentPane(newContentPane);frame.pack();frame.setVisible(true);