BCSL-043 ASSIGNMENT SOLUTION (2019-20)

If you have any queries please leave a message here
Your Message
×


Q1. Write java program to find the factorial of a given number. Define appropriate class and methods in your program.

Answer : -

import java.io.*;
public class Factorial
{
public static void main(String args[])throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the number : ");
int n = Integer.parseInt(br.readLine());
int fact = 1;
for(int i=1;i<=n;i++)
{
fact = fact * i;
}
System.out.println("Factorial of " + n + " = " + fact);
}
}




Q2. Write a program in java to read the content from a text file and count the number of words in the file.

Answer : -

/* Java FileReader class is used to read data from the file. It returns data in byte format. */
import java.io.*;
public class WordCount
{
public static void main(String args[])throws Exception
{
/* Creates a new FileReader */
FileReader fr = new FileReader("D:\\Test.txt");
int i, temp=-1, count=0;
/* int read( ) method is used to return a character in ASCII form. */
while ((i=fr.read()) != -1)
{
// 9 → Horizontal Tab
// 10 → Line Feed (New Line)
// 13 → Carriage Return (Enter Key)
// 32 → Space
if(i==9 || i==10 || i==13 || i==32)
{
temp = i;
}
else
{
if(temp==9 || temp==10 || temp==13 || temp==32)
{
count++;
}
temp = i;
}
}
if(temp!=9 && temp!=10 && temp!=13 && temp!=32)
{
count++;
}
System.out.println("Total Words = " + count);
}
}




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.

Answer : -

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class GenerateTable extends Applet
{
int count, n, i;
TextField t;
public void init()
{
t = new TextField(10);
add(t);
t.setText("");
}
public void paint(Graphics g)
{
String str;
g.drawString("Enter the number", 100, 20);
try
{
str = t.getText();
n = Integer.parseInt(str);
}
catch(Exception e) { }
if(n>=11 && n<=90 && n%2==0)
{
count=100;
for(i=1;i<=10;i++)
{
g.drawString(i + " * " + n + " = " + (i*n), 100, count);
count = count + 20;
}
}
}
public boolean action(Event event, Object obj)
{
repaint();
return true;
}
}



ABOUT US

QuestionSolves.com is an educational website that helps worldwide students in solving computer education related queries.

Also, different software like Visual Studio, SQL Server, Oracle etc. are available to download in different versions.

Moreover, QuestionSolves.com provides solutions to your questions and assignments also.


MORE TOPIC


Windows Command

UNIX Command

IGNOU Assignment Solution

IGNOU Question Paper Solution

Solutions of Different Questions


WHAT WE DO


Website Devlopment

Training

Home Learning

Provide BCA, MCA Projects

Provide Assignment & Question Paper Solution


CONTACT US


Follow Us