0% found this document useful (0 votes)
5 views4 pages

Java Coding: Even/Odd Tables & Factors

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

Java Coding: Even/Odd Tables & Factors

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Logical coding:

[Link] tables: 2 to 20:


public class EvenTables {

public static void main(String[] args)


{
for (int i = 1; i <= 10; i++) {
int even = 2 * i;
for (int j = 1; j <= 10; j++) {
[Link](even + "X"
+ j + "=" + even * j);

}
[Link]();
}
}

}
2. Odd Tables By taking input from
customer:

import [Link];

public class OddTables {


public static void main(String[] args)
{
Scanner sc = new Scanner([Link]);
[Link]("Please enter how
many tables you want: ");
int o = [Link]();
[Link]("Please enter at
which point to stop like 10X10=100: ");
int e = [Link]();
for (int j = 1; j <= e; j++) {
for (int i = 1; i <= o; i++) {
int odd = 2 * i - 1;

[Link]("%d X %d =
%d\t", odd, j, (odd * j));
}
[Link]();
}

[Link]();
}
}
3. Factors: By taking input from
customer:
import [Link];

public class Factors {

public static void main(String[] args)


{
Scanner scanner = new
Scanner([Link]);
[Link]("Enter a positive
number to find its factors: ");
int customerNumber =
[Link]();
if (customerNumber > 0) {
printFactors(customerNumber);
} else {
[Link]("Please enter
a valid positive number.");
}
[Link]();

}
private static void printFactors(int
customerNumber) {
int i=1;
while(i<=customerNumber/2) {
if(customerNumber%i==0) {
[Link](i +" ");
}
i++;
}
[Link](customerNumber);
[Link]();
}

You might also like