Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
12 views43 pages

Computer File

The document is an acknowledgment and project report by a student, thanking various individuals for their support in completing a programming project. It includes an index of topics covered, such as Perfect Numbers, Armstrong Numbers, and functions related to 1D and 2D arrays, along with code snippets and variable descriptions for each program. The document demonstrates the student's learning and application of programming concepts through various examples.

Uploaded by

kholivirat6191
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views43 pages

Computer File

The document is an acknowledgment and project report by a student, thanking various individuals for their support in completing a programming project. It includes an index of topics covered, such as Perfect Numbers, Armstrong Numbers, and functions related to 1D and 2D arrays, along with code snippets and variable descriptions for each program. The document demonstrates the student's learning and application of programming concepts through various examples.

Uploaded by

kholivirat6191
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 43

ACKNOWLEDGEMENT

I <Student Name> of class <Section> would like to


express my heartfelt gratitude to our principal Ma’am
Amita Singh for letting us portray our creativity and
for inspiring us to fulfill the task given to us with full
enthusiasm .
I would like to thank Sir Manvendra Shah our
computer teacher for guiding and motivating us
through the project. I also thank my parents for
making available the material that was required for
making the project and also helping me to make
research for the topics.
I thank my friends for compiling the project and
giving me encouragement for the completion of it.
Above I sincerely thank God for the unhindered
finishing of this project.

<Student Name>
<Section>
INDEX
S.NO TOPIC
1 Perfect Number
2 Armstrong Number
3 Special Number
4 Palindrome Number
5 Lucky Number
6 1D Array
7 Sum of 1D Array Elements
8 2 D Array
9 Sum of 2D Array
10 Diagonally sum of 2D Array
11 Reverse of word(String)
12 Get any character from word
(String)
13 Pattern Printing
14 Function
15 Series
16 Bibliography
Program to print Perfect
Number
import java.util.Scanner;
public class PerfectNumber
{
public static void main()
{
long n, sum=0;
Scanner sc=new Scanner(System.in);
System.out.print("Enter the number: ");
n=sc.nextLong();
int i=1;
while(i <= n/2)
{
if(n % i == 0)
{
Sum = sum + i;
}
i++;
}
if(sum==n)
{
System.out.println(n+" is a perfect number.");
}
else{
System.out.println(n+" is not a perfect number.");
}
}
}
Variable Description Table

S.No Variable Data type Description


1 sum long To store sum of
digits
2 n long To get user
input
3 i int For the loop

Output
Program to print Armstrong
Number
import java.util.Scanner;
public class ArmstsrongNumber
{
static boolean isArmstrong(int n)
{
int temp, digits=0, last=0, sum=0;
temp=n;
while(temp>0)
{
temp = temp/10;
digits++;
}
temp = n;
while(temp>0)
{
last = temp % 10;
sum += (Math.pow(last, digits));
temp = temp/10;
}
if(n==sum)
return true;
else return false;
}
public static void main(String args[])
{
int num;
Scanner sc= new Scanner(System.in);
System.out.println("Enter the number: ");
num=sc.nextInt();
if(isArmstrong(num))
{
System.out.print("Armstrong ");
}
else
{
System.out.print("Not Armstrong ");
}
}
}
Variable Description Table
s.no variable Data Type Description
1 temp int Copy of input
numbers
2 digit int To counts
digits
3 last int To store last
digit
4 sum int To add cube of
digit
5 num int To store user
number

Output
Program to print Special
Number
import java.util.Scanner;
public class SpecialNumber
{
public static void main()
{
int num, number, last_digit, sum_Of_Fact = 0;
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number: ");
number = sc.nextInt();
num = number;
while (number > 0)
{
last_digit = number % 10;
int fact=1;
//factorial logic
for(int i=1; i<=last_digit; i++)
{
fact=fact*i;
}
//calculates the sum of all factorials
sum_Of_Fact = sum_Of_Fact + fact;
number = number / 10;
}
if(num==sum_Of_Fact)
{
System.out.println(num+ " is a special number.");
}
else
{
System.out.println(num+ " is not a special number.");
}
}
}
Variable Description Table

S.No Variable Data Type Description


1 num int Copy of input
numbers
2 number int To store user
number
3 last _digit int To store last digit
4 sum_of_Fa int To add factorial of
ct
digit
5 fact int To calculate
factorial

Output
Program to print Palindrome
Number
import java.util.*;
public class Palindrome{
public static void main(){
Scanner sc=new Scanner (System.in);
System.out.println("Enter any
Number :"); long a=sc.nextLong(); long
l=a;
long k=0;
while(l!=0){
long p=l%10;
k=(k*10)+p;
l=l/10;
}
l=a;
if(k==l){
System.out.println("It's a palindrome number.");
}else{
System.out.println("It's not a palindrome number.");
}
}
}
Variable Description Table

S.No Variable Data Type Description


1 a long To store user
number
2 l long To store the value in
variable a
3 p long To store last digit of
a
number
4 k long To store the reverse
of a
number

Output
Program to print Lucky
Number
import java.util.*;
public class LuckyNumber
{
public static int count = 2;
static boolean isLuckyNumber(int n)
{
if(count > n)
return true;
if(n%count == 0)
return false;
n = n-(n/count);
count++;
return isLuckyNumber(n);
}
public static void main ()
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter the number: ");
int num=sc.nextInt();
if(isLuckyNumber(num))
System.out.println(num+" is a Lucky Number.");
else
System.out.println(num+" is not a Lucky Number.");
}
}
Variable Description Table

S.No variable Data type description


1 count int To check number
2 N int Function variable
3 num int to store user
number

Output
Program to create 1D-Array
import java.util.Scanner;

public class OneDArray

public static void main()

Scanner sc=new Scanner(System.in);

System.out.print("Enter the number of elements you want to


store: ");

int n=sc.nextInt();

int[] array = new int[10];

System.out.println("Enter the elements of the array: ");

for(int i=0; i<n; i++)

{
array[i]=sc.nextInt();

System.out.println("Array elements are: ");

for (int i=0; i<n; i++)

System.out.println(array[i]);

}
Variable Description Table

S.No Variable Data Type Description


1 n int To store the size of
array
2 i int To Run the loops
3 array int To store the
elements

Output
Program to calculate sum of elements of
1D Array

import java.util.Scanner;
public class ArraySum {
public static void main() {
Scanner sc = new Scanner(System.in);

System.out.print("Enter the size of the array: ");


int size = sc.nextInt();
int[] arr = new int[size];

System.out.println("Enter the elements of the


array:"); for (int i = 0; i < size; i++)
{ System.out.print("Element " + (i + 1) + ": "); arr[i]
= sc.nextInt();
}
int sum = 0;
for (int i = 0; i < size; i++) {
sum += arr[i];
}
System.out.println("Sum of all elements in the array: " +
sum);
}
}
Variable Description Table

S.No Variable Data Type Description


1 size int To store user
number
2 arr int[] to store elements
input by the user
3 i int Used for loops

4 sum int The sum of all


elements in the
array

Output
Program to create 2D-Array
import java.util.Scanner;

public class Print2DArray {

public static void main(){

Scanner sc = new Scanner(System.in);

System.out.print("Enter the number of rows: ");

int rows = sc.nextInt();

System.out.print("Enter the number of columns: ");

int cols = sc.nextInt();

double[][] array = new double[rows][cols];

System.out.println("Enter the elements of the

array:"); for (int i = 0; i < rows; i++) { for (int j = 0; j

< cols; j++) {

array[i][j] = sc.nextDouble();

}
}

System.out.println("The 2D array

is:"); for (int i = 0; i < rows; i++) {

for (int j = 0; j < cols; j++)

{ System.out.print(array[i][j] + "

"); }

System.out.println();

}
Variable Description Table

s.no variable Data Type Description


1 rows int User input for rows
2 cols int User input for
column
3 array double[][] Elements entered by
user
4 i int For outer loop
5 j int For inner loop

Output
Program to calculate sum of 2D Array
elements

import java.util.Scanner;
public class SumOf2DArray {
public static void main(String[] args) { Scanner
scanner = new Scanner(System.in);
System.out.print("Enter the number of rows: "); int
rows = scanner.nextInt(); System.out.print("Enter
the number of columns: "); int cols =
scanner.nextInt();
double[][] array = new double[rows][cols];
System.out.println("Enter the elements of the
array:"); for (int i = 0; i < rows; i++) { for (int j = 0; j
< cols; j++) {
array[i][j] = scanner.nextDouble();
}
}
double sum = 0;
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
sum += array[i][j];
}
}
System.out.println("The sum of all elements in the 2D array
is: " + sum);
}
}
Variable Description Table
s no. variable Data type Description
1. rows int User input for
rows
2. cols int User input for
columns
3. array double Elements entered
by user
4. i int For outer loop

5. j int For inner loop

6. sum double For storing the


sum of elements

Output
Program to calculate Diagonally
sum of 2D Array

import java.util.Scanner;
public class Diagonal_sumOfElements
{ public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter number of rows: ");
int r= sc.nextInt();
System.out.print("Enter number of columns: ");
int c= sc.nextInt();
int sum=0;int sum1=0;
int[][] matrix = new int[r][c];
System.out.println("Enter elements of the matrix:");
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
matrix[i][j] = sc.nextInt();
}
}
System.out.println("The matrix
is:"); for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++)
{ System.out.print(matrix[i][j] + "\
t");
}
System.out.println();
}

System.out.println("\nDiagonal elements of the matrix:");


if (r == c) {
for (int i = 0; i < r; i++) {
for(int j=0;j<r;j++){
if(i==j){
sum=sum+matrix[i][j];

}
if(i+j==r-1){
sum1=sum1+matrix[i][j];
}
}
}
System.out.println("Sum of Left diagonal ="+sum+" and "+"Sum of
Right diagonal ="+sum1);
} else {
System.out.println("The matrix is not square. Sum of
Diagonal elements cannot be calculated!!!");
}

}
}
Variable Description Table

S.No Variable Data Type Description


1 R Int Number of rows in
the 2D array
2 C Int Number of
columns in the 2D
array
3 matrix int[][] 2D array
containing integer
elements
4 i,j int Loop variables for
iterating rows
and columns of
the matrix
respectively

Output
Program to reverse a word
import java.util.*;
class ReverseWord{
public static void main (String[] args) {
Scanner sc=new Scanner (System.in);
System.out.println("Enter any word:");
String a=sc.next();
String n="";

char ch;
System.out.print("Original word: ");
System.out.println(a);
for (int i=0; i<a.length(); i++)
{
ch= a.charAt(i);
n= ch+n;
}
System.out.println("Reversed word: "+ n);
}
}

Variable Description Table

S.No Variable Data Type Description


1 A String Input of original
word

2 N String Input of reversed


word
3 Ch char To store the
characters
of a word
4 I Int To run the loop
Output
Program of Finding character from a word
import java.util.*;
class FindingCharacter {
public static char Char(String k, int index)
{
return k.charAt(index);
}
public static void main()
{
Scanner sc=new Scanner (System.in);
System.out.println("Enter the word:");
String s=sc.next();
System.out.println("Enter the number from left to right(like:abcd;
Letter at number 3= 'c') where the letter is lying in the word:");
int index=sc.nextInt();
char ch =Char(s, index-1);
System.out.println("Character from " + s + " at index "
+ index + " is : " + ch);
}
}

Variable Description Table

S.No Variable Data Type Description


1 K String To store the word
2 Index int To get the index of
the
letter in a word from
user
3 Ch char To store the word
and
index of letter
4 S String To take input of
word form user

Output
Program of the Pattern of Triangle

import java .util.Scanner;


public class Triangle{
public static void main(){
for(int i=1;i<=5;i++)
{
for(int j=1;j<=5-i;j++)
{
System.out.print(" ");
}
for(int k=1;k<=i;k++){
System.out.print("*"+" ");
}
System.out.println();
}
}
Variable Description Table

S.No Variable Data Type Description


1 I int For rows(outer loop)
2 J int For columns(inner
loop)
3 K int For printing stars
(another[3rd]loop)

Output
Program of Function (Overloading)
import java.util.*;
public class Function
{
static int Fact(int num){
int k=1
for(int i=num;i>=1;i--){
k=k*i;
}
return k;
}
public static void main(){
Scanner sc=new Scanner(System.in);
System.out.println("Enter any number:");
int a=sc.nextInt();
int y=Function.Fact(a);
System.out.println("Factorial of "+a+":"+y);
}
}

Variable Description Table

S.No Variable Data Type Description


1 Num int To store the number
2 A int To take input of
number
from user
3 K int To store the factorial
of a
number
4 Y int To store the value of
k
5 I int For the loop

Output
Program To print the Series
import java.util.Scanner;
public class Series//Series is 1/2+3/4+…
{
public static void main()
{
Scanner sc=new Scanner (System.in);
System.out.println("Enter the number");
int n=sc.nextInt();
double sum=0.0;double k=0.0;double p=1.0;
for(int i=1;i<=n;i++){
if(i%2==0){
p=i;
}else{
k=i;
}
sum=sum+k/p;
}
System.out.println(sum);
}
}
Variable Description Table

S.No Variable Data Type Description


1 n int To take input of term
from user
2 sum double To store the sum of
series
3 k int To store the odd
numbers
4 p int To store the even
numbers
5 i int For the loop

Output
BIBLIOGRAPHY
Books:

• Guided Computer Applications (ICSE) class X


-DN Publications
Websites:

• https://www.greeksforgreeks.org

You might also like