Vous êtes sur la page 1sur 4

/* Week 4 : a) Write a Java program that reads a file name from the user, then d

isplays information about whether the file exists, whether the file is readable,
whether the file is writable, the type of file and the length of the file in by
tes. */

import java.io.*;
import java.util.*;
public class LabPro8
{
public static void main(String args[])
{
File f=new File(args[0]);
System.out.println("Filename " +f.getName());
System.out.println("Filepath " +f.getPath());
System.out.println("Parent " +f.getName());
System.out.println("File size " +f.length()+" bytes");
System.out.println("is readable " +f.canRead());
System.out.println("is Writable " +f.canWrite());
System.out.println("is directory " +f.isDirectory());
System.out.println("is file " +f.isFile());
}
}

implements of stack adt


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
{
int stack[]=new int[n];
int top=-1;
public void push()
{
try{
DataInputStream dis=new DataInputStream(System.in);
if(top==(n-1))
{
System.out.println("overflow");
return;
}
else
{
System.out.println("enter element");
int ele=Integer.parseInt(dis.readLine());
stack[++top]=ele;
}
}
catch(Exception e)
{
System.out.println("e");
}
}
public void pop()
{
if(top<0)
{
System.out.println("underflow");
return;
}
else
{
int popper=stack[top];
top--;
System.out.println("popped element" +popper);
}
}
public void peek()
{
if(top<0)
{
System.out.println("underflow");
return:
}
else
{
int popper=stack[top];
System.out.println("popped element" +popper);
}
}
public void display()
{
if(top<0)
{
System.out.println("empty");
return;
}
else
{
String str=" ";
for(int i=0;i<=top;i++)
str=str+" "+stack[i];
System.out.println("elements are"+str);
}
}
}
class Stackadt
{
public static void main(String arg[])throws IOException
{
DataInputStream dis=new DataInputStream(System.in);
Stackimp stk=new Stackimp();
int ch=0;
do{
System.out.println("enter ur choice for 1.push 2.pop
3.peek 4.peek 5.display );
ch=Integer.parseInt(dis.readLine());
switch(ch){
case 1:stk.push();
break;
case 2:stk.pop();
break;
case 3:stk.peek();
break;
case 4:stk.display();
break;
case 5:System.exit(0);
}
}while(ch<=5);
}
}

hello evryone etc program

public class ThreadEx {


public static void main(String[] args) {
Thread t1 = new Thread(new Runnable() {
public void run() {
while(true) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Good Morning ");
}
}
});
Thread t2 = new Thread(new Runnable() {
public void run() {
while(true) {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Hello ");
}
}
});
t1.start();
t2.start();
while(true) {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Welcome ");
}
}
}