Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Advanced Java Practical Slip 17 Answers

 



A) Write a java program to accept a String from user and display each vowel from a

String after 3 seconds.

Answer :

import java.io.*;

 

public class Slip17A {

    public static void main(String args[]) {

        alpha a1 = new alpha();

        a1.start();

    }

}

 

class alpha extends Thread {

    public void run(){

        try{

            DataInputStream din = new DataInputStream(System.in);

            System.out.print("Enter String : ");

            String str = din.readLine();

            String str1 = str.toLowerCase();

            for(int i=0; i<=str1.length(); i++){

                if(str1.charAt(i)=='a' || str1.charAt(i)=='e'|| str1.charAt(i)=='i' || str1.charAt(i)=='o' || str1.charAt(i)=='u' ){

                    System.out.println(str1.charAt(i));

                    sleep(3000);

                }

            }

           

        }catch(Exception e){}

    }

}

B) Write a Java program to check whether given file is present on server or not, if it is

 there then display its contents on client’s terminal otherwise display the message “File

 Not Found”.

Answer :

Server file

import java.io.*;

import java.net.*;

 

public class Server {

 

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

 

        ServerSocket ss = new ServerSocket(5400);

 

        while (true) {

            Socket s = ss.accept();

            DataOutputStream dos = new DataOutputStream(s.getOutputStream());

            File f = new File("E:\addvans-java\src\jsp\server.text");

 

            if (f.exists()) {

                Scanner sc = new Scanner(f);

                while (sc.hasNextLine()) {

 

                    String str = sc.nextLine();

 

                    dos.writeUTF(f.getName() + " = file content = " + str);

 

                }

 

            } else {

                String stra = "file is not Exists on SERVER";

                dos.writeUTF(" Error -- " + stra);

            }

        }

    }

}

 

 

client file


import java.net.*;

import java.io.*;

 

public class Client {

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

 

        Socket s = new Socket("localhost", 5400);

 

        DataInputStream dis = new DataInputStream(s.getInputStream());

 

        System.out.print("result = ");

        System.out.print(dis.readUTF());

 

    }

}

Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Advanced Java Practical Slip 17 Answers Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Advanced Java Practical Slip 17 Answers Reviewed by technical_saurabh on December 15, 2022 Rating: 5

No comments:

Powered by Blogger.