0% found this document useful (0 votes)
37 views8 pages

Fundamentals of Computer Science IN2203-G6

This document contains an assignment with 5 tasks to write Java programs. The tasks include programs to: 1) Calculate the Fibonacci sequence. 2) Generate a multiplication table for the number 6. 3) Calculate the factorial of a given number. 4) Check if a number is prime. 5) Calculate the standard deviation of an array of numbers. The document provides the required Java code for each task and expected output. It also lists the names and student IDs of 5 students submitting the assignment.

Uploaded by

Dilpreet Boparai
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)
37 views8 pages

Fundamentals of Computer Science IN2203-G6

This document contains an assignment with 5 tasks to write Java programs. The tasks include programs to: 1) Calculate the Fibonacci sequence. 2) Generate a multiplication table for the number 6. 3) Calculate the factorial of a given number. 4) Check if a number is prime. 5) Calculate the standard deviation of an array of numbers. The document provides the required Java code for each task and expected output. It also lists the names and student IDs of 5 students submitting the assignment.

Uploaded by

Dilpreet Boparai
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/ 8

Running head: ASSIGNMENT 1 1

Program + Course Name


Section Code
Semester Fundamentals of Computer
IN2203-G6
ISBA II Science

Type of Evaluation Percentage Weight of Total

Assignment #1 (Online Evaluation


Winter 2021
Assignment) 15%

Course
Due Date
Instructor Total Marks: /15
Week 6 (Feb 15, 2021)
Abiodun Ojo

Student Name: Dilpreet Kaur Student ID #: 201906298

Student Name: Narmada Kethireddy Student ID #: 201906957

Student Name: Jaideep Singh Student ID #: 201906773

Student Name: Rattan Kaushal Student ID #: 201906803

Student Name: Sushant Singh Student ID #: 201904652

Instructions:

Design and document your response. Zip your codes along with your response back in this

document, and SUBMIT it back using Google Classroom once completed.


ASSIGNMENT 1 2

Tasks

1. This is Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21, Write Java program to solve

the task.

Java code:

class Fibonacci{

public static void main(String args[])

int n1=0,n2=1,n3,i,count=10;

System.out.print(n1+" "+n2); //printing 0 and 1

for(i=2;i<count;++i)

n3=n1+n2;

System.out.print(" "+n3);

n1=n2;

n2=n3;

Output:
ASSIGNMENT 1 3

2. Write a Java program to Generate the Multiplication table below

6*1=6

6 * 2 = 12

6 * 3 = 18

6 * 4 = 24

6 * 5 = 30

6 * 6 = 36

6 * 7 = 42

6 * 8 = 48

6 * 9 = 56

6* 10 = 60

Java Code:

public class Table

public static void main(String[] args) {

int num =6;

for(int a=1; a<=10; ++a)


ASSIGNMENT 1 4

System.out.printf("%d * %d = %d \n",num,a,num * a);

Output:

3. Factorial of n (n!) = 1 * 2 * 3 * 4 * ... * n. Write a Java program to find it.

Java code

import java.util.Scanner;

class Factorial{

public static void main(String args[]){

int i,fact=1;

int num;

Scanner sc = new Scanner(System.in);

System.out.println("\n Enter num");

num=sc.nextInt();

for(i=1;i<=num;i++){

fact = fact*i;

System.out.println("\n Factorial of "+num+" is "+fact);


ASSIGNMENT 1 5

} }

Output:

4. A prime number is a number divisible by only 1 and itself. Write a prime number

codes using Java.

Java Code:

public class Prime{

static void checkPrime(int n){

int i,m=0,flag=0;

m=n/2;

if(n==0||n==1){

System.out.println(n+" is not prime number");

}else{

for(i=2;i<=m;i++){

if(n%i==0){
ASSIGNMENT 1 6

System.out.println(n+" is not prime number");

flag=1;

break;

if(flag==0) { System.out.println(n+" is prime number"); }

}//end of else

Output:

5. Program to Find Standard Deviation:

Java Code:

public class StandardDeviation {

public static void main(String[] args) {


ASSIGNMENT 1 7

int[] array = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };

double standardDeviation = calculateStandardDeviation(array);

System.out.format("Standard deviation : %.6f", standardDeviation);

private static double calculateStandardDeviation(int[] array)

// finding the sum of array values

double sum = 0.0;

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

sum += array[i];

// getting the mean of array.

double mean = sum / array.length;

// calculating the standard deviation

double standardDeviation = 0.0;

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

standardDeviation += Math.pow(array[i] - mean, 2);

return Math.sqrt(standardDeviation/array.length);

Output:
ASSIGNMENT 1 8

You might also like