BCSL-043 Java Programming Lab Solved Assignment 2019-20 PDF

Title BCSL-043 Java Programming Lab Solved Assignment 2019-20
Author Raj Aniket
Course Income Tax Law And Practice
Institution University of Delhi
Pages 5
File Size 202.1 KB
File Type PDF
Total Downloads 40
Total Views 162

Summary

Assignment of IGNOU BCA University hshbsjsbshsjhsb shshshsbbaj sshshhssjsjs jshbssbsbsjsjsb bsbsbsbsh hshshsbsbssjs jshshsbsshshe hehehehd shshshsbsbrh hdhdhsbdbdbdbdbd jsshehebebsnsnsnsnsjsjsjsjdjsjdnenene dnejejeej...


Description

www.techiya.in

www.techiya.in BCA Solved Assignment 2019-20 Course Code : BCSL-043 Course Title : Java Programming Lab Assignment Number: BCA(4)/BCSL-043/Assignment/2019-20

Q1. Write java program to find the factorial of a given number. Define appropriate class and methods in your program. Ans: import java.util.Scanner; class Factorial{ public static void main(String args[]){ //Scanner object for capturing the user input Scanner scanner = new Scanner(System.in); System.out.println("Enter the number:"); //Stored the entered value in variable int num = scanner.nextInt(); //Called the user defined function fact int factorial = fact(num); System.out.println("Factorial of entered number is: "+factorial); } static int fact(int n) { int output; if(n==1){ return 1; } //Recursion: Function calling itself!! output = fact(n-1)* n; return output; } }

1 www.techiya.in

www.techiya.in

Output:

Q2. Write a program in java to read the content from a text file and count the number of words in the file. Ans: import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; public class FileWordCount { public static void main(String[] args) throws IOException { File f1=new File("input.txt"); //Creation of File Descriptor for input file String[] words=null; //Intialize the word Array int wc=0; //Intialize word count to zero FileReader fr = new FileReader(f1); //Creation of File Reader object

2 www.techiya.in

www.techiya.in

BufferedReader br = new BufferedReader(fr); //Creation of BufferedReader object String s; while((s=br.readLine())!=null) //Reading Content from the file { words=s.split(" "); //Split the word using space wc=wc+words.length; //increase the word count for each word } fr.close(); System.out.println("Number of words in the file:" +wc); //Print the word count } } Output:

Q3. Create an applet which take a number as input. If the number is between 11-90 and is an even number then display its table otherwise ask for other number as input. Ans: GenerateTable.java import java.applet.*; 3 www.techiya.in

www.techiya.in

import java.awt.*; import java.awt.event.*; public class GenerateTable extends Applet { int count,n,i; TextField t1; public void init() { t1 = new TextField(10); add(t1); t1.setText(""); } public void paint(Graphics g) { String str; g.drawString("Enter the number",100,20); try { str=t1.getText(); n=Integer.parseInt(str); } catch(Exception e) { } if(n>=1 && n...


Similar Free PDFs