[go: up one dir, main page]

0% found this document useful (0 votes)
14 views4 pages

Set 8

The document contains 5 code examples demonstrating different Java programming concepts including Fibonacci series, multithreading, object-oriented programming with classes and objects, applets, and file input/output streams.

Uploaded by

html backup
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views4 pages

Set 8

The document contains 5 code examples demonstrating different Java programming concepts including Fibonacci series, multithreading, object-oriented programming with classes and objects, applets, and file input/output streams.

Uploaded by

html backup
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

1)

import java.util.Scanner;
class p8_1
{
public static void main(String args[])
{
int f,s,t,num;
Scanner sc=new Scanner(System.in);

System.out.println("enter number : ");


num=sc.nextInt();

f=0;
s=1;

System.out.print(f);
System.out.print(s);

for(int i=2;i<num;i++)
{
t=f+s;
System.out.print(t);
f=s;
s=t;
}
}
}

2)
class VII2_thread extends Thread {

String msg;

public VII2_thread(String msg) {


this.msg = msg;
start();
}

public void run() {


System.out.println(msg);
}

public static void main(String[] args) {

VII2_thread t1 = new VII2_thread("How do you do ?");


VII2_thread t2 = new VII2_thread("Fine, Thank you!");
}
}
OR
class Thread1 extends Thread {

public void run() {


System.out.println("how do you do?");
}
}

class Thread2 extends Thread {

public void run() {


System.out.println("fine! Thank you !");
}
}

class VII2_thread {
public static void main(String args[]) {

Thread1 t1 = new Thread1();


Thread2 t2 = new Thread2();

t1.start();
t2.start();

}
}

3)

import java.util.Scanner;

class Student
{
int id;
String name;
Scanner sc=new Scanner(System.in);

void setdata()
{
System.out.println("enter student id : ");
id=sc.nextInt();

sc.nextLine();

System.out.println("enter student name : ");


name=sc.nextLine();
}
void display()
{
System.out.println("student id : "+id);
System.out.println("student name : "+name);
}
}
class P8_3
{
public static void main(String args[])
{
Student s[]=new Student[5];
int i;

for(i=0;i<5;i++)
{
s[i]=new Student();
}

for(i=0;i<5;i++)
{
s[i].setdata();
}

for(i=0;i<5;i++)
{
s[i].display();
}
}
}

4)

import java.applet.Applet;
import java.awt.*;

public class P8_4 extends Applet


{
public void paint(Graphics g)
{
g.drawOval(30,70,50,50);
g.drawRect(45,85,20,20);
}
}

/*
<applet code="P8_4" height=500 width=500>
</applet>
*/

5)

import java.io.*;

public class P8_5{

public static void main(String[] args) throws IOException{

FileOutputStream file = new FileOutputStream("xyz.txt");

DataOutputStream data = new DataOutputStream(file);

data.writeInt(69);
data.writeDouble(34.35);
data.writeChar('a');
data.writeBoolean(false);
data.flush();
data.close();

FileInputStream file1 = new FileInputStream("xyz.txt");

DataInputStream in = new DataInputStream(file1);

System.out.println(in.readInt());
System.out.println(in.readDouble());
System.out.println(in.readChar());
System.out.println(in.readBoolean());

in.close();
}
}

You might also like