do help to modify this code. I want my output as multiplication table for even numbers.

import java.util.Scanner;

class Tables
{
public static void main(String args[])
{
int a, b, c, d;

System.out.println("Enter range of numbers to print their multiplication table");
Scanner in = new Scanner(System.in);

a = in.nextInt();
b = in.nextInt();

for (c = a; c <= b; c++) {
  System.out.println("Multiplication table of "+c);

  for (d = 1; d <= 10; d++) {
     System.out.println(c+"*"+d+" = "+(c*d));
  }
}

}
}

I’m not sure if I understand your problem correctly but you are trying to print a multiplication table for even numbers based on the given input ‘a’ & ‘b’, right? If it is, maybe the below modification is what you’re looking for

    import java.util.Scanner;
    
    class Tables { 
    	public static void main(String args[]) 
    	{ 
    		int a, b, c, d;
    
    		System.out.print("Enter range of numbers to print their multiplication table: ");
    		Scanner in = new Scanner(System.in);
    
    		a = in.nextInt();
    		b = in.nextInt();
    
    		a = (a % 2 != 0 ? a+1 : a);
    		b = (b % 2 != 0 ? b-1 : b);
    
    		System.out.print("\t  ");
    		for(c = a; c <= b; c+=2)
    			System.out.print(c + "\t \t");
    		System.out.println("\n");
    
    		for (c = a; c <= b; c+=2) {
    			  System.out.print(c + "\t| ");
    			  for (d = a; d <= b; d+=2) {
    			     System.out.print((c*d) + "\t|\t");
    			  }
    			  System.out.println();
    		}
    	} 
    }

Hmm…anyway thank you. But i want output look like this 1x6=6 2x6=12…until 10x6=60 then 1x8=8 2x8=16…10x8=80 then start back 1x10=10 2x10=20 until 10x10=100. :frowning: my code’s output looks 1x6=6 2x6=12…until 10x6=60 then 1x7=7…until 10x10=100. :frowning:

if that’s the case, just change your code to this


a = (a % 2 != 0 ? a+1 : a);
b = (b % 2 != 0 ? b-1 : b);

for (c = a; c <= b; c+=2) {
  // other code here
}

and also i want my input in list form. no matter what number i click as input,the output must be the multiplication of even number. your code is correct. but how can modify it for make it in list form and start from 1x6=6… ? sorry to bother you…

@vinita06 ignore my first code. I have a new comment above where my 2nd code is indicated. Just put that code to your original code. Hope it helps! :slight_smile:

Thank you so much…it helps me alot…Once again thank you very much :slight_smile:

@vinita06 You’re welcome. I hope it solved your problem :slight_smile:

a = (a 2 != 0 ? a+1 : a); b = (b 2 != 0 ? b-1 : b);
is there any other way to write this command?