SlideShare a Scribd company logo
1 of 4
Download to read offline
// PrimeFactorization.java
import java.text.DecimalFormat;
import java.util.Scanner;
public class PrimeFactorization
{
public static void prime(int product)
{
System.out.print("Prime Factorization: ");
int i=2;
int count = 0;
int temp = i;
while(product>=1)
{
if(product%i == 0)
{
count++;
product=product/i;
}
else
{
if(count > 0)
System.out.print(i + "^"+ count+" ");
count = 0;
i++;
}
}
System.out.println();
}
public static void main(String [] args)
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter integers: ");
int number = sc.nextInt();
if(number < 0)
{
System.out.println("Bad Input");
System.exit(1);
}
int product = number;
while(true)
{
number = sc.nextInt();
if(number < 0 )
break;
else
product = product * number;
}
System.out.println("Product: " + product);
prime(product);
}
}
/*
output:
Enter integers: 882 18 26 -45
Product: 412776
Prime Factorization: 2^3 3^4 7^2 13^1
Enter integers: 19 -5
Product: 19
Prime Factorization: 19^1
Enter integers: -37 99 124 22 -65
Bad Input
*/
Solution
// PrimeFactorization.java
import java.text.DecimalFormat;
import java.util.Scanner;
public class PrimeFactorization
{
public static void prime(int product)
{
System.out.print("Prime Factorization: ");
int i=2;
int count = 0;
int temp = i;
while(product>=1)
{
if(product%i == 0)
{
count++;
product=product/i;
}
else
{
if(count > 0)
System.out.print(i + "^"+ count+" ");
count = 0;
i++;
}
}
System.out.println();
}
public static void main(String [] args)
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter integers: ");
int number = sc.nextInt();
if(number < 0)
{
System.out.println("Bad Input");
System.exit(1);
}
int product = number;
while(true)
{
number = sc.nextInt();
if(number < 0 )
break;
else
product = product * number;
}
System.out.println("Product: " + product);
prime(product);
}
}
/*
output:
Enter integers: 882 18 26 -45
Product: 412776
Prime Factorization: 2^3 3^4 7^2 13^1
Enter integers: 19 -5
Product: 19
Prime Factorization: 19^1
Enter integers: -37 99 124 22 -65
Bad Input
*/

More Related Content

Similar to PrimeFactorization.javaimport java.text.DecimalFormat; import.pdf

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
 
SumNumbers.java import java.util.Scanner;public class SumNumbe.pdf
SumNumbers.java import java.util.Scanner;public class SumNumbe.pdfSumNumbers.java import java.util.Scanner;public class SumNumbe.pdf
SumNumbers.java import java.util.Scanner;public class SumNumbe.pdfankkitextailes
 
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
 
PrintDiamond.javaimport java.util.Scanner;class PrintDiamond.pdf
 PrintDiamond.javaimport java.util.Scanner;class PrintDiamond.pdf PrintDiamond.javaimport java.util.Scanner;class PrintDiamond.pdf
PrintDiamond.javaimport java.util.Scanner;class PrintDiamond.pdfapexelectronices01
 
Anjalisoorej imca133 assignment
Anjalisoorej imca133 assignmentAnjalisoorej imca133 assignment
Anjalisoorej imca133 assignmentAnjaliSoorej
 
Presentation1 computer shaan
Presentation1 computer shaanPresentation1 computer shaan
Presentation1 computer shaanwalia Shaan
 
the code below is a recommendation system application to suggest a s.pdf
the code below is a recommendation system application to suggest a s.pdfthe code below is a recommendation system application to suggest a s.pdf
the code below is a recommendation system application to suggest a s.pdfrajatchugh13
 
Driver.java import java.util.Scanner; import java.text.Decimal.pdf
Driver.java import java.util.Scanner; import java.text.Decimal.pdfDriver.java import java.util.Scanner; import java.text.Decimal.pdf
Driver.java import java.util.Scanner; import java.text.Decimal.pdfanandhomeneeds
 
Write a Java ProgramSolutionAnswer- Code- import java-io--- import jav.docx
Write a Java ProgramSolutionAnswer- Code- import java-io--- import jav.docxWrite a Java ProgramSolutionAnswer- Code- import java-io--- import jav.docx
Write a Java ProgramSolutionAnswer- Code- import java-io--- import jav.docxlez31palka
 
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
 
import java.util.Scanner;public class Digits { public static v.pdf
import java.util.Scanner;public class Digits { public static v.pdfimport java.util.Scanner;public class Digits { public static v.pdf
import java.util.Scanner;public class Digits { public static v.pdfapexelectronices01
 
The sample program for above series in JAVA will be like belowimpo.pdf
The sample program for above series in JAVA will be like belowimpo.pdfThe sample program for above series in JAVA will be like belowimpo.pdf
The sample program for above series in JAVA will be like belowimpo.pdfrajat630669
 
The sample program for above series in JAVA will be like belowimpo.pdf
The sample program for above series in JAVA will be like belowimpo.pdfThe sample program for above series in JAVA will be like belowimpo.pdf
The sample program for above series in JAVA will be like belowimpo.pdfrajat630669
 
1.aimport java.util.Scanner;public class Diamond {   public st.pdf
1.aimport java.util.Scanner;public class Diamond {   public st.pdf1.aimport java.util.Scanner;public class Diamond {   public st.pdf
1.aimport java.util.Scanner;public class Diamond {   public st.pdfaparnatiwari291
 
import java.util.; public class DecimalToBinary { public stat.pdf
import java.util.; public class DecimalToBinary { public stat.pdfimport java.util.; public class DecimalToBinary { public stat.pdf
import java.util.; public class DecimalToBinary { public stat.pdfanithareadymade
 

Similar to PrimeFactorization.javaimport java.text.DecimalFormat; import.pdf (20)

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
 
Java file
Java fileJava file
Java file
 
Java file
Java fileJava file
Java file
 
SumNumbers.java import java.util.Scanner;public class SumNumbe.pdf
SumNumbers.java import java.util.Scanner;public class SumNumbe.pdfSumNumbers.java import java.util.Scanner;public class SumNumbe.pdf
SumNumbers.java import java.util.Scanner;public class SumNumbe.pdf
 
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
 
Programs of java
Programs of javaPrograms of java
Programs of java
 
PrintDiamond.javaimport java.util.Scanner;class PrintDiamond.pdf
 PrintDiamond.javaimport java.util.Scanner;class PrintDiamond.pdf PrintDiamond.javaimport java.util.Scanner;class PrintDiamond.pdf
PrintDiamond.javaimport java.util.Scanner;class PrintDiamond.pdf
 
Anjalisoorej imca133 assignment
Anjalisoorej imca133 assignmentAnjalisoorej imca133 assignment
Anjalisoorej imca133 assignment
 
Java programs
Java programsJava programs
Java programs
 
Presentation1 computer shaan
Presentation1 computer shaanPresentation1 computer shaan
Presentation1 computer shaan
 
the code below is a recommendation system application to suggest a s.pdf
the code below is a recommendation system application to suggest a s.pdfthe code below is a recommendation system application to suggest a s.pdf
the code below is a recommendation system application to suggest a s.pdf
 
07-Basic-Input-Output.ppt
07-Basic-Input-Output.ppt07-Basic-Input-Output.ppt
07-Basic-Input-Output.ppt
 
Driver.java import java.util.Scanner; import java.text.Decimal.pdf
Driver.java import java.util.Scanner; import java.text.Decimal.pdfDriver.java import java.util.Scanner; import java.text.Decimal.pdf
Driver.java import java.util.Scanner; import java.text.Decimal.pdf
 
Write a Java ProgramSolutionAnswer- Code- import java-io--- import jav.docx
Write a Java ProgramSolutionAnswer- Code- import java-io--- import jav.docxWrite a Java ProgramSolutionAnswer- Code- import java-io--- import jav.docx
Write a Java ProgramSolutionAnswer- Code- import java-io--- import jav.docx
 
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
 
import java.util.Scanner;public class Digits { public static v.pdf
import java.util.Scanner;public class Digits { public static v.pdfimport java.util.Scanner;public class Digits { public static v.pdf
import java.util.Scanner;public class Digits { public static v.pdf
 
The sample program for above series in JAVA will be like belowimpo.pdf
The sample program for above series in JAVA will be like belowimpo.pdfThe sample program for above series in JAVA will be like belowimpo.pdf
The sample program for above series in JAVA will be like belowimpo.pdf
 
The sample program for above series in JAVA will be like belowimpo.pdf
The sample program for above series in JAVA will be like belowimpo.pdfThe sample program for above series in JAVA will be like belowimpo.pdf
The sample program for above series in JAVA will be like belowimpo.pdf
 
1.aimport java.util.Scanner;public class Diamond {   public st.pdf
1.aimport java.util.Scanner;public class Diamond {   public st.pdf1.aimport java.util.Scanner;public class Diamond {   public st.pdf
1.aimport java.util.Scanner;public class Diamond {   public st.pdf
 
import java.util.; public class DecimalToBinary { public stat.pdf
import java.util.; public class DecimalToBinary { public stat.pdfimport java.util.; public class DecimalToBinary { public stat.pdf
import java.util.; public class DecimalToBinary { public stat.pdf
 

More from APMRETAIL

The Periodic table of elements are classified through color dependi.pdf
 The Periodic table of elements are classified through color dependi.pdf The Periodic table of elements are classified through color dependi.pdf
The Periodic table of elements are classified through color dependi.pdfAPMRETAIL
 
#include iostream #include string #include invalidHr.h.pdf
 #include iostream #include string #include invalidHr.h.pdf #include iostream #include string #include invalidHr.h.pdf
#include iostream #include string #include invalidHr.h.pdfAPMRETAIL
 
option D) answer A and B are both correct .pdf
                     option   D) answer A and B are both correct      .pdf                     option   D) answer A and B are both correct      .pdf
option D) answer A and B are both correct .pdfAPMRETAIL
 
image not visible clearly. please give points to .pdf
                     image not visible clearly. please give points to .pdf                     image not visible clearly. please give points to .pdf
image not visible clearly. please give points to .pdfAPMRETAIL
 
HI(g) has the highest molar entropy as it has h.pdf
                     HI(g)  has the highest molar entropy  as it has h.pdf                     HI(g)  has the highest molar entropy  as it has h.pdf
HI(g) has the highest molar entropy as it has h.pdfAPMRETAIL
 
ion-dipole Solution ion-.pdf
                     ion-dipole  Solution                     ion-.pdf                     ion-dipole  Solution                     ion-.pdf
ion-dipole Solution ion-.pdfAPMRETAIL
 
Yes. It has SP2 hybridisation , with 2 lone pairs.pdf
                     Yes. It has SP2 hybridisation , with 2 lone pairs.pdf                     Yes. It has SP2 hybridisation , with 2 lone pairs.pdf
Yes. It has SP2 hybridisation , with 2 lone pairs.pdfAPMRETAIL
 
Using, M1V1 = M2V2 10.0 x 0.1106 = M2 x 13.64 M.pdf
                     Using, M1V1 = M2V2  10.0 x 0.1106 = M2 x 13.64  M.pdf                     Using, M1V1 = M2V2  10.0 x 0.1106 = M2 x 13.64  M.pdf
Using, M1V1 = M2V2 10.0 x 0.1106 = M2 x 13.64 M.pdfAPMRETAIL
 
The start of the European Colonization is typically dated to 1492, a.pdf
The start of the European Colonization is typically dated to 1492, a.pdfThe start of the European Colonization is typically dated to 1492, a.pdf
The start of the European Colonization is typically dated to 1492, a.pdfAPMRETAIL
 
The institutions which act as mediator between savers and boorrowers.pdf
The institutions which act as mediator between savers and boorrowers.pdfThe institutions which act as mediator between savers and boorrowers.pdf
The institutions which act as mediator between savers and boorrowers.pdfAPMRETAIL
 
Solution Mitochondria is known as power house of the cell.It prod.pdf
Solution Mitochondria is known as power house of the cell.It prod.pdfSolution Mitochondria is known as power house of the cell.It prod.pdf
Solution Mitochondria is known as power house of the cell.It prod.pdfAPMRETAIL
 
Sewage before being disposed of either in river stream or on land, h.pdf
Sewage before being disposed of either in river stream or on land, h.pdfSewage before being disposed of either in river stream or on land, h.pdf
Sewage before being disposed of either in river stream or on land, h.pdfAPMRETAIL
 
Relational database was proposed by Edgar Codd (of IBM Research) aro.pdf
Relational database was proposed by Edgar Codd (of IBM Research) aro.pdfRelational database was proposed by Edgar Codd (of IBM Research) aro.pdf
Relational database was proposed by Edgar Codd (of IBM Research) aro.pdfAPMRETAIL
 
Option “D” is not true about the net neutrality.Favouring of net n.pdf
Option “D” is not true about the net neutrality.Favouring of net n.pdfOption “D” is not true about the net neutrality.Favouring of net n.pdf
Option “D” is not true about the net neutrality.Favouring of net n.pdfAPMRETAIL
 
NaF will dissociate 100, and therefore the F- will have extra 0.25 .pdf
NaF will dissociate 100, and therefore the F- will have extra 0.25 .pdfNaF will dissociate 100, and therefore the F- will have extra 0.25 .pdf
NaF will dissociate 100, and therefore the F- will have extra 0.25 .pdfAPMRETAIL
 
CO2 because the heaviest would have the most attr.pdf
                     CO2 because the heaviest would have the most attr.pdf                     CO2 because the heaviest would have the most attr.pdf
CO2 because the heaviest would have the most attr.pdfAPMRETAIL
 
Intensity of light source Io = 1000 countsIntensity after absorpti.pdf
Intensity of light source Io = 1000 countsIntensity after absorpti.pdfIntensity of light source Io = 1000 countsIntensity after absorpti.pdf
Intensity of light source Io = 1000 countsIntensity after absorpti.pdfAPMRETAIL
 
I hereby explain the SDU (service data unit )and PDU ( protocol data.pdf
I hereby explain the SDU (service data unit )and PDU ( protocol data.pdfI hereby explain the SDU (service data unit )and PDU ( protocol data.pdf
I hereby explain the SDU (service data unit )and PDU ( protocol data.pdfAPMRETAIL
 
Hop1 = 13, p2 = 13, and p3 = 13Ha at least one p is not equal.pdf
Hop1 = 13, p2 = 13, and p3 = 13Ha at least one p is not equal.pdfHop1 = 13, p2 = 13, and p3 = 13Ha at least one p is not equal.pdf
Hop1 = 13, p2 = 13, and p3 = 13Ha at least one p is not equal.pdfAPMRETAIL
 

More from APMRETAIL (20)

The Periodic table of elements are classified through color dependi.pdf
 The Periodic table of elements are classified through color dependi.pdf The Periodic table of elements are classified through color dependi.pdf
The Periodic table of elements are classified through color dependi.pdf
 
#include iostream #include string #include invalidHr.h.pdf
 #include iostream #include string #include invalidHr.h.pdf #include iostream #include string #include invalidHr.h.pdf
#include iostream #include string #include invalidHr.h.pdf
 
option D) answer A and B are both correct .pdf
                     option   D) answer A and B are both correct      .pdf                     option   D) answer A and B are both correct      .pdf
option D) answer A and B are both correct .pdf
 
image not visible clearly. please give points to .pdf
                     image not visible clearly. please give points to .pdf                     image not visible clearly. please give points to .pdf
image not visible clearly. please give points to .pdf
 
HI(g) has the highest molar entropy as it has h.pdf
                     HI(g)  has the highest molar entropy  as it has h.pdf                     HI(g)  has the highest molar entropy  as it has h.pdf
HI(g) has the highest molar entropy as it has h.pdf
 
ion-dipole Solution ion-.pdf
                     ion-dipole  Solution                     ion-.pdf                     ion-dipole  Solution                     ion-.pdf
ion-dipole Solution ion-.pdf
 
Yes. It has SP2 hybridisation , with 2 lone pairs.pdf
                     Yes. It has SP2 hybridisation , with 2 lone pairs.pdf                     Yes. It has SP2 hybridisation , with 2 lone pairs.pdf
Yes. It has SP2 hybridisation , with 2 lone pairs.pdf
 
Using, M1V1 = M2V2 10.0 x 0.1106 = M2 x 13.64 M.pdf
                     Using, M1V1 = M2V2  10.0 x 0.1106 = M2 x 13.64  M.pdf                     Using, M1V1 = M2V2  10.0 x 0.1106 = M2 x 13.64  M.pdf
Using, M1V1 = M2V2 10.0 x 0.1106 = M2 x 13.64 M.pdf
 
O=C=O .pdf
                     O=C=O                                      .pdf                     O=C=O                                      .pdf
O=C=O .pdf
 
The start of the European Colonization is typically dated to 1492, a.pdf
The start of the European Colonization is typically dated to 1492, a.pdfThe start of the European Colonization is typically dated to 1492, a.pdf
The start of the European Colonization is typically dated to 1492, a.pdf
 
The institutions which act as mediator between savers and boorrowers.pdf
The institutions which act as mediator between savers and boorrowers.pdfThe institutions which act as mediator between savers and boorrowers.pdf
The institutions which act as mediator between savers and boorrowers.pdf
 
Solution Mitochondria is known as power house of the cell.It prod.pdf
Solution Mitochondria is known as power house of the cell.It prod.pdfSolution Mitochondria is known as power house of the cell.It prod.pdf
Solution Mitochondria is known as power house of the cell.It prod.pdf
 
Sewage before being disposed of either in river stream or on land, h.pdf
Sewage before being disposed of either in river stream or on land, h.pdfSewage before being disposed of either in river stream or on land, h.pdf
Sewage before being disposed of either in river stream or on land, h.pdf
 
Relational database was proposed by Edgar Codd (of IBM Research) aro.pdf
Relational database was proposed by Edgar Codd (of IBM Research) aro.pdfRelational database was proposed by Edgar Codd (of IBM Research) aro.pdf
Relational database was proposed by Edgar Codd (of IBM Research) aro.pdf
 
Option “D” is not true about the net neutrality.Favouring of net n.pdf
Option “D” is not true about the net neutrality.Favouring of net n.pdfOption “D” is not true about the net neutrality.Favouring of net n.pdf
Option “D” is not true about the net neutrality.Favouring of net n.pdf
 
NaF will dissociate 100, and therefore the F- will have extra 0.25 .pdf
NaF will dissociate 100, and therefore the F- will have extra 0.25 .pdfNaF will dissociate 100, and therefore the F- will have extra 0.25 .pdf
NaF will dissociate 100, and therefore the F- will have extra 0.25 .pdf
 
CO2 because the heaviest would have the most attr.pdf
                     CO2 because the heaviest would have the most attr.pdf                     CO2 because the heaviest would have the most attr.pdf
CO2 because the heaviest would have the most attr.pdf
 
Intensity of light source Io = 1000 countsIntensity after absorpti.pdf
Intensity of light source Io = 1000 countsIntensity after absorpti.pdfIntensity of light source Io = 1000 countsIntensity after absorpti.pdf
Intensity of light source Io = 1000 countsIntensity after absorpti.pdf
 
I hereby explain the SDU (service data unit )and PDU ( protocol data.pdf
I hereby explain the SDU (service data unit )and PDU ( protocol data.pdfI hereby explain the SDU (service data unit )and PDU ( protocol data.pdf
I hereby explain the SDU (service data unit )and PDU ( protocol data.pdf
 
Hop1 = 13, p2 = 13, and p3 = 13Ha at least one p is not equal.pdf
Hop1 = 13, p2 = 13, and p3 = 13Ha at least one p is not equal.pdfHop1 = 13, p2 = 13, and p3 = 13Ha at least one p is not equal.pdf
Hop1 = 13, p2 = 13, and p3 = 13Ha at least one p is not equal.pdf
 

Recently uploaded

MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayMakMakNepo
 

Recently uploaded (20)

MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up Friday
 

PrimeFactorization.javaimport java.text.DecimalFormat; import.pdf

  • 1. // PrimeFactorization.java import java.text.DecimalFormat; import java.util.Scanner; public class PrimeFactorization { public static void prime(int product) { System.out.print("Prime Factorization: "); int i=2; int count = 0; int temp = i; while(product>=1) { if(product%i == 0) { count++; product=product/i; } else { if(count > 0) System.out.print(i + "^"+ count+" "); count = 0; i++; } } System.out.println(); } public static void main(String [] args) { Scanner sc=new Scanner(System.in); System.out.print("Enter integers: "); int number = sc.nextInt(); if(number < 0)
  • 2. { System.out.println("Bad Input"); System.exit(1); } int product = number; while(true) { number = sc.nextInt(); if(number < 0 ) break; else product = product * number; } System.out.println("Product: " + product); prime(product); } } /* output: Enter integers: 882 18 26 -45 Product: 412776 Prime Factorization: 2^3 3^4 7^2 13^1 Enter integers: 19 -5 Product: 19 Prime Factorization: 19^1 Enter integers: -37 99 124 22 -65 Bad Input */ Solution // PrimeFactorization.java import java.text.DecimalFormat; import java.util.Scanner;
  • 3. public class PrimeFactorization { public static void prime(int product) { System.out.print("Prime Factorization: "); int i=2; int count = 0; int temp = i; while(product>=1) { if(product%i == 0) { count++; product=product/i; } else { if(count > 0) System.out.print(i + "^"+ count+" "); count = 0; i++; } } System.out.println(); } public static void main(String [] args) { Scanner sc=new Scanner(System.in); System.out.print("Enter integers: "); int number = sc.nextInt(); if(number < 0) { System.out.println("Bad Input"); System.exit(1); }
  • 4. int product = number; while(true) { number = sc.nextInt(); if(number < 0 ) break; else product = product * number; } System.out.println("Product: " + product); prime(product); } } /* output: Enter integers: 882 18 26 -45 Product: 412776 Prime Factorization: 2^3 3^4 7^2 13^1 Enter integers: 19 -5 Product: 19 Prime Factorization: 19^1 Enter integers: -37 99 124 22 -65 Bad Input */