0% found this document useful (0 votes)
6 views

Logical Coding

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Logical Coding

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Logical coding:

1.Even 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++) {
System.out.println(even + "X"
+ j + "=" + even * j);

}
System.out.println();
}
}

}
2. Odd Tables By taking input from
customer:

import java.util.Scanner;

public class OddTables {


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

System.out.printf("%d X %d =
%d\t", odd, j, (odd * j));
}
System.out.println();
}

sc.close();
}
}
3. Factors: By taking input from
customer:
import java.util.Scanner;

public class Factors {

public static void main(String[] args)


{
Scanner scanner = new
Scanner(System.in);
System.out.print("Enter a positive
number to find its factors: ");
int customerNumber =
scanner.nextInt();
if (customerNumber > 0) {
printFactors(customerNumber);
} else {
System.out.println("Please enter
a valid positive number.");
}
scanner.close();

}
private static void printFactors(int
customerNumber) {
int i=1;
while(i<=customerNumber/2) {
if(customerNumber%i==0) {
System.out.println(i +" ");
}
i++;
}
System.out.println(customerNumber);
System.out.println();
}

You might also like