wap in java to compute the sum of all the factor of integers using while loop
Answers
Answer:
public class Main {
public static void main(String[] args) {
// positive number
int number = 60;
System.out.print("Factors of " + number + " are: ");
// loop runs from 1 to 60
for (int i = 1; i <= number; ++i) {
// if number is divided by i
// i is the factor
if (number % i == 0) {
System.out.print(i + " ");
}
}
}
}
Output
Factors of 60 are: 1 2 3 4 5 6 10 12 15 20 30 60
Explanation:
hope you are satisfied with the answer
Answer:
import java.util.Scanner;
class brainly
{
public static void main(String[] args)
{
try
{
Scanner sc = new Scanner(System.in);
boolean b=true;
while(b==true)
{
int number,i=1;
System.out.print("Enter a positive integer: ");
number=sc.nextInt();
for(;;)
{
int tmp=++i;
if ( number % tmp == 0)
{
System.out.println(i);
}
if(i<=0)
{
System.exit(10);
}
}
}
}
catch(ArithmeticException e)
{
System.out.println("Program finished");
}
}
}