Write a Java program to Find Factors of a Number using For loop using Java programming language.
I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me in the following email address for further details. If you want to advertise on my website kindly contact me also in my email address also. Thank you.
My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.
My mobile number here in the Philippines is 09173084360.Please subscribe to my channel https://www.youtube.com/channel/UCOs-lpOoIeJoh6gpJthPoGg
Thank you very much for your support.
Program Listing
factors.java
/* Write a Java program to Find Factors of a Number using For loop */
import java.util.Scanner;
public class factors {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int x=0, i=0;
char ch;
do {
System.out.println();
System.out.print("\tFactors of a Number Using For Loop in Java");
System.out.println("\n");
System.out.print("\tGive a Positive Number : ");
x = input.nextInt();
System.out.println();
System.out.print("\tThe factors of the " + x + " are: ");
for (i = 1; i <= x; ++i) {
if (x % i == 0) {
System.out.print(i + " ");
}
++i;
}
System.out.print("\n\n");
System.out.print("\tDo you want to continue (Type y or n) : ");
ch = input.next().charAt(0);
} while (ch == 'Y'|| ch == 'y');
System.out.println("\n");
System.out.print("\tTHANK YOU FOR USING THIS PROGRAM");
System.out.println("\n\n");
input.close();
}
}
No comments:
Post a Comment