×

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

 0 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)); } }  } } asked 27 Jul '17, 18:28 0★vinita06 1●1 accept rate: 0%

 0 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(); } } }  answered 27 Jul '17, 19:06 11●3 accept rate: 0% 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. :( my code's output looks 1x6=6 2x6=12....until 10x6=60 then 1x7=7....until 10x10=100. :( (27 Jul '17, 19:34) vinita060★ 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 }  (27 Jul '17, 19:41) 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.. (27 Jul '17, 19:42) vinita060★ @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! :) (27 Jul '17, 19:46) Thank you so much..it helps me alot..Once again thank you very much :) (27 Jul '17, 20:19) vinita060★ @vinita06 You're welcome. I hope it solved your problem :) (27 Jul '17, 20:26) a = (a % 2 != 0 ? a+1 : a); b = (b % 2 != 0 ? b-1 : b); is there any other way to write this command? (29 Jul '17, 18:47) vinita060★ showing 5 of 7 show all
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×1,220
×37
×26
×5

question asked: 27 Jul '17, 18:28

question was seen: 354 times

last updated: 29 Jul '17, 18:47