SlideShare a Scribd company logo
1 of 13
Group A (All are Compulsory)
Fundamentals of JAVA Programming Lab
Write some simple programs in Java such as:
i) To find factorial of number.
ii) To display first 50 prime numbers.
iii) To find sum and average of N numbers
i) To find factorial of number
• The factorial of a positive number n is given by:
• factorial of n (n!) = 1 * 2 * 3 * 4 * ... * n
i) To find factorial of number.
public class Factorial {
public static void main(String[] args) {
int num = 10;
long factorial = 1;
for(int i = 1; i <= num; ++i)
{
// factorial = factorial * i;
factorial *= i;
}
System.out.printf("Factorial of %d = %d", num, factorial);
}
}
i) To find factorial of number
Output
Factorial of 10 = 3628800
i) To find factorial of number
public class Factorial {
public static void main(String[] args) {
int num = 5, i = 1;
long factorial = 1;
while(i <= num)
{
factorial *= i;
i++;
}
System.out.printf("Factorial of %d = %d", num, factorial);
}
}
To display first 50 prime numbers
• Program to display first 50 prime numbers
• To display the first 50 prime numbers, you can either enter n value as
50 in the above
To display first 50 prime numbers
class PrimeNumberDemo
{
public static void main(String args[])
{
int n;
int status = 1;
int num = 3;
System.out.println("First 50 prime numbers are:");
System.out.println(2);
To display first 50 prime numbers
for ( int i = 2 ; i <=50 ; )
{
for ( int j = 2 ; j <= Math.sqrt(num) ; j++ )
{
if ( num%j == 0 )
{
status = 0;
break;
}
}
To display first 50 prime numbers
if ( status != 0 )
{
System.out.println(num);
i++;
}
status = 1;
num++;
}
}
}
iii)To find sum and average of N numbers
import java.util.Scanner;
public class Sum_Average
{
public static void main(String[] args)
{
int n, sum = 0;
float average;
Scanner s = new Scanner(System.in);
To find sum and average of N numbers
System.out.print("Enter no. of elements you want in array:");
n = s.nextInt();
int a[] = new int[n];
System.out.println("Enter all the elements:");
for(int i = 0; i < n ; i++)
{
a[i] = s.nextInt();
sum = sum + a[i];
}
To find sum and average of N numbers
System.out.println("Sum:"+sum);
average = (float)sum / n;
System.out.println("Average:"+average);
}
}

More Related Content

Similar to EXPT1.pptx

Java AssignmentWrite a program using sortingsorting bubble,sele.pdf
Java AssignmentWrite a program using sortingsorting bubble,sele.pdfJava AssignmentWrite a program using sortingsorting bubble,sele.pdf
Java AssignmentWrite a program using sortingsorting bubble,sele.pdfeyewatchsystems
 
Computer java programs
Computer java programsComputer java programs
Computer java programsADITYA BHARTI
 
Java Simple Programs
Java Simple ProgramsJava Simple Programs
Java Simple ProgramsUpender Upr
 
week4_python.docx
week4_python.docxweek4_python.docx
week4_python.docxRadhe Syam
 
import java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdfimport java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdfoptokunal1
 
Sharable_Java_Python.pdf
Sharable_Java_Python.pdfSharable_Java_Python.pdf
Sharable_Java_Python.pdfICADCMLTPC
 
An input file A1-txt is given which contains a list of integer values-.docx
An input file A1-txt is given which contains a list of integer values-.docxAn input file A1-txt is given which contains a list of integer values-.docx
An input file A1-txt is given which contains a list of integer values-.docxlauracallander
 
Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
 Problem1 java codeimport java.util.Scanner; Java code to pr.pdf Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
Problem1 java codeimport java.util.Scanner; Java code to pr.pdfanupamfootwear
 
Presentation1 computer shaan
Presentation1 computer shaanPresentation1 computer shaan
Presentation1 computer shaanwalia Shaan
 
Java™ (OOP) - Chapter 5: "Methods"
Java™ (OOP) - Chapter 5: "Methods"Java™ (OOP) - Chapter 5: "Methods"
Java™ (OOP) - Chapter 5: "Methods"Gouda Mando
 
Codeimport java.util.Random; import java.util.Scanner;public .pdf
Codeimport java.util.Random; import java.util.Scanner;public .pdfCodeimport java.util.Random; import java.util.Scanner;public .pdf
Codeimport java.util.Random; import java.util.Scanner;public .pdfanupamfootwear
 
Anjalisoorej imca133 assignment
Anjalisoorej imca133 assignmentAnjalisoorej imca133 assignment
Anjalisoorej imca133 assignmentAnjaliSoorej
 
Object Oriented Programming - Value Types & Reference Types
Object Oriented Programming - Value Types & Reference TypesObject Oriented Programming - Value Types & Reference Types
Object Oriented Programming - Value Types & Reference TypesDudy Ali
 
Presentation 6 (1).pptx
Presentation 6 (1).pptxPresentation 6 (1).pptx
Presentation 6 (1).pptxSagarGhosh48
 
Factors.javaimport java.io.; import java.util.Scanner; class .pdf
Factors.javaimport java.io.; import java.util.Scanner; class .pdfFactors.javaimport java.io.; import java.util.Scanner; class .pdf
Factors.javaimport java.io.; import java.util.Scanner; class .pdfdeepakangel
 
Write the program in MIPS that declares an array of positive integer.pdf
Write the program in MIPS that declares an array of positive integer.pdfWrite the program in MIPS that declares an array of positive integer.pdf
Write the program in MIPS that declares an array of positive integer.pdfarihanthtoysandgifts
 

Similar to EXPT1.pptx (20)

Java AssignmentWrite a program using sortingsorting bubble,sele.pdf
Java AssignmentWrite a program using sortingsorting bubble,sele.pdfJava AssignmentWrite a program using sortingsorting bubble,sele.pdf
Java AssignmentWrite a program using sortingsorting bubble,sele.pdf
 
C programs
C programsC programs
C programs
 
Computer java programs
Computer java programsComputer java programs
Computer java programs
 
Java Simple Programs
Java Simple ProgramsJava Simple Programs
Java Simple Programs
 
types.pdf
types.pdftypes.pdf
types.pdf
 
week4_python.docx
week4_python.docxweek4_python.docx
week4_python.docx
 
import java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdfimport java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdf
 
Sharable_Java_Python.pdf
Sharable_Java_Python.pdfSharable_Java_Python.pdf
Sharable_Java_Python.pdf
 
An input file A1-txt is given which contains a list of integer values-.docx
An input file A1-txt is given which contains a list of integer values-.docxAn input file A1-txt is given which contains a list of integer values-.docx
An input file A1-txt is given which contains a list of integer values-.docx
 
Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
 Problem1 java codeimport java.util.Scanner; Java code to pr.pdf Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
 
Presentation1 computer shaan
Presentation1 computer shaanPresentation1 computer shaan
Presentation1 computer shaan
 
Java™ (OOP) - Chapter 5: "Methods"
Java™ (OOP) - Chapter 5: "Methods"Java™ (OOP) - Chapter 5: "Methods"
Java™ (OOP) - Chapter 5: "Methods"
 
Codeimport java.util.Random; import java.util.Scanner;public .pdf
Codeimport java.util.Random; import java.util.Scanner;public .pdfCodeimport java.util.Random; import java.util.Scanner;public .pdf
Codeimport java.util.Random; import java.util.Scanner;public .pdf
 
Java practical
Java practicalJava practical
Java practical
 
Anjalisoorej imca133 assignment
Anjalisoorej imca133 assignmentAnjalisoorej imca133 assignment
Anjalisoorej imca133 assignment
 
Object Oriented Programming - Value Types & Reference Types
Object Oriented Programming - Value Types & Reference TypesObject Oriented Programming - Value Types & Reference Types
Object Oriented Programming - Value Types & Reference Types
 
Presentation 6 (1).pptx
Presentation 6 (1).pptxPresentation 6 (1).pptx
Presentation 6 (1).pptx
 
Factors.javaimport java.io.; import java.util.Scanner; class .pdf
Factors.javaimport java.io.; import java.util.Scanner; class .pdfFactors.javaimport java.io.; import java.util.Scanner; class .pdf
Factors.javaimport java.io.; import java.util.Scanner; class .pdf
 
6_Array.pptx
6_Array.pptx6_Array.pptx
6_Array.pptx
 
Write the program in MIPS that declares an array of positive integer.pdf
Write the program in MIPS that declares an array of positive integer.pdfWrite the program in MIPS that declares an array of positive integer.pdf
Write the program in MIPS that declares an array of positive integer.pdf
 

More from swagatkarve

Revised-SOP-FOR-UG-AFFILIATED-01.01.2021.pdf
Revised-SOP-FOR-UG-AFFILIATED-01.01.2021.pdfRevised-SOP-FOR-UG-AFFILIATED-01.01.2021.pdf
Revised-SOP-FOR-UG-AFFILIATED-01.01.2021.pdfswagatkarve
 
Unit No. 1 Artificial Intelligence Overview.pptx
Unit No. 1 Artificial Intelligence Overview.pptxUnit No. 1 Artificial Intelligence Overview.pptx
Unit No. 1 Artificial Intelligence Overview.pptxswagatkarve
 
Unit 2. Image Enhancement in Spatial Domain.pptx
Unit 2. Image Enhancement in Spatial Domain.pptxUnit 2. Image Enhancement in Spatial Domain.pptx
Unit 2. Image Enhancement in Spatial Domain.pptxswagatkarve
 
CN PPT MMZ 9 Jan 2024.pptx
CN PPT MMZ 9 Jan 2024.pptxCN PPT MMZ 9 Jan 2024.pptx
CN PPT MMZ 9 Jan 2024.pptxswagatkarve
 
Intro to Subject.pptx
Intro to Subject.pptxIntro to Subject.pptx
Intro to Subject.pptxswagatkarve
 
Spatial Domain Filtering.pdf
Spatial Domain Filtering.pdfSpatial Domain Filtering.pdf
Spatial Domain Filtering.pdfswagatkarve
 
Lab Charts .pptx
Lab Charts .pptxLab Charts .pptx
Lab Charts .pptxswagatkarve
 
Unit 3 testing of logic circuits
Unit 3 testing of logic circuitsUnit 3 testing of logic circuits
Unit 3 testing of logic circuitsswagatkarve
 
Unit no. 5 cmos logic design
Unit no. 5 cmos logic designUnit no. 5 cmos logic design
Unit no. 5 cmos logic designswagatkarve
 
Vlsi design mc qs
Vlsi design mc qsVlsi design mc qs
Vlsi design mc qsswagatkarve
 

More from swagatkarve (11)

Revised-SOP-FOR-UG-AFFILIATED-01.01.2021.pdf
Revised-SOP-FOR-UG-AFFILIATED-01.01.2021.pdfRevised-SOP-FOR-UG-AFFILIATED-01.01.2021.pdf
Revised-SOP-FOR-UG-AFFILIATED-01.01.2021.pdf
 
Unit No. 1 Artificial Intelligence Overview.pptx
Unit No. 1 Artificial Intelligence Overview.pptxUnit No. 1 Artificial Intelligence Overview.pptx
Unit No. 1 Artificial Intelligence Overview.pptx
 
Unit 2. Image Enhancement in Spatial Domain.pptx
Unit 2. Image Enhancement in Spatial Domain.pptxUnit 2. Image Enhancement in Spatial Domain.pptx
Unit 2. Image Enhancement in Spatial Domain.pptx
 
CN PPT MMZ 9 Jan 2024.pptx
CN PPT MMZ 9 Jan 2024.pptxCN PPT MMZ 9 Jan 2024.pptx
CN PPT MMZ 9 Jan 2024.pptx
 
Intro to Subject.pptx
Intro to Subject.pptxIntro to Subject.pptx
Intro to Subject.pptx
 
Spatial Domain Filtering.pdf
Spatial Domain Filtering.pdfSpatial Domain Filtering.pdf
Spatial Domain Filtering.pdf
 
Lab Charts .pptx
Lab Charts .pptxLab Charts .pptx
Lab Charts .pptx
 
osi.ppt
osi.pptosi.ppt
osi.ppt
 
Unit 3 testing of logic circuits
Unit 3 testing of logic circuitsUnit 3 testing of logic circuits
Unit 3 testing of logic circuits
 
Unit no. 5 cmos logic design
Unit no. 5 cmos logic designUnit no. 5 cmos logic design
Unit no. 5 cmos logic design
 
Vlsi design mc qs
Vlsi design mc qsVlsi design mc qs
Vlsi design mc qs
 

Recently uploaded

Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxhumanexperienceaaa
 

Recently uploaded (20)

Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
 

EXPT1.pptx

  • 1. Group A (All are Compulsory) Fundamentals of JAVA Programming Lab
  • 2. Write some simple programs in Java such as: i) To find factorial of number. ii) To display first 50 prime numbers. iii) To find sum and average of N numbers
  • 3. i) To find factorial of number • The factorial of a positive number n is given by: • factorial of n (n!) = 1 * 2 * 3 * 4 * ... * n
  • 4. i) To find factorial of number. public class Factorial { public static void main(String[] args) { int num = 10; long factorial = 1; for(int i = 1; i <= num; ++i) { // factorial = factorial * i; factorial *= i; } System.out.printf("Factorial of %d = %d", num, factorial); } }
  • 5. i) To find factorial of number Output Factorial of 10 = 3628800
  • 6. i) To find factorial of number public class Factorial { public static void main(String[] args) { int num = 5, i = 1; long factorial = 1; while(i <= num) { factorial *= i; i++; } System.out.printf("Factorial of %d = %d", num, factorial); } }
  • 7. To display first 50 prime numbers • Program to display first 50 prime numbers • To display the first 50 prime numbers, you can either enter n value as 50 in the above
  • 8. To display first 50 prime numbers class PrimeNumberDemo { public static void main(String args[]) { int n; int status = 1; int num = 3; System.out.println("First 50 prime numbers are:"); System.out.println(2);
  • 9. To display first 50 prime numbers for ( int i = 2 ; i <=50 ; ) { for ( int j = 2 ; j <= Math.sqrt(num) ; j++ ) { if ( num%j == 0 ) { status = 0; break; } }
  • 10. To display first 50 prime numbers if ( status != 0 ) { System.out.println(num); i++; } status = 1; num++; } } }
  • 11. iii)To find sum and average of N numbers import java.util.Scanner; public class Sum_Average { public static void main(String[] args) { int n, sum = 0; float average; Scanner s = new Scanner(System.in);
  • 12. To find sum and average of N numbers System.out.print("Enter no. of elements you want in array:"); n = s.nextInt(); int a[] = new int[n]; System.out.println("Enter all the elements:"); for(int i = 0; i < n ; i++) { a[i] = s.nextInt(); sum = sum + a[i]; }
  • 13. To find sum and average of N numbers System.out.println("Sum:"+sum); average = (float)sum / n; System.out.println("Average:"+average); } }