SlideShare ist ein Scribd-Unternehmen logo
1 von 4
Downloaden Sie, um offline zu lesen
// 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
*/

Weitere ähnliche Inhalte

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
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
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
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
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
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
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 

Kürzlich hochgeladen (20)

Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
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
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.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
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
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
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 

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 */