GTU OOP Program - 8

8). Write a program that reads an integer and displays all its smallest factors in increasing order. For example, if input number is 120, the output should be as follows:2,2,2,3,5.

  1. import java.util.Scanner;
  2.  
  3. class Program_08 {
  4. public static void main(String[] args) {
  5.  
  6. Scanner input = new Scanner(System.in);
  7.  
  8. System.out.print("Enter an integer: ");
  9. int num = input.nextInt();
  10. int index = 2; // Num to test as factors
  11.  
  12. // finding all the smallest factors
  13. while (num / index != 1) {
  14. // Test as a factor of num
  15. if (num % index == 0) {
  16. System.out.print(index + ", ");
  17. num /= index;
  18. } else {
  19. index++;
  20. }
  21.  
  22. }
  23. System.out.println(num + ".");
  24. }
  25. }
  26.  
Output
cse gtu, gtu study material for computer engineering students gujarat technological university oop lab manual solution

gtu oop lab manual,

oop GTU Practical,

oop Programs,

Object oriented Programming,

Gtu study material 3140705,

OOP 3140705,

oop practical list,

Java Programming,

gtu oop practical,

oop lab solution gtu

Comments

YouTube

Popular posts from this blog

GTU OS Program - 11 Filters

GTU OS Program - 8

GTU OS Program - 13 Date Validator