Printing and Loop Practice
Collapse Content
Show Content
You are the programmer in charge of the multiplication table team. You will be given two numbers, a
and b
. Can you print all the multiples of a
from a
through a*b? Please them on one line, separated by spaces.
Challenge
Print the numbers from a
through a*b.
Please sign in or sign up to submit answers.
Alternatively, you can try out Learneroo before signing up.
Comments
David
Jan 9, 3:28 PMI am getting runtime error everytime System.out.println(); is being executed.
Learneroo
Jan 9, 7:27 PM@David, your code looks like it runs ok. How would you print the next different multiple of
a
each time, when you have an indexi
that increases each time?David
Jan 9, 7:35 PMHi, thanks for the answer. The runtime error was showing up before I clicked reset, seems it cached some error? Anyway great work this website.
Tom Stevens
Jan 13, 8:52 AMCan you tell me what I've done wrong in the code below:
For (int index=a, index=<b, int index = index + 1){
a*i=answer;}
System.out.println(answer);
Learneroo
Jan 13, 11:28 AMTo fix the syntax errors, replace
=<
with<=
and remove the secondint
since you've already declaredindex
as an int in the beginning. You can click on the buttons on the side for help with syntax.Dino Šišić
Feb 19, 4:00 PMif someone is looking for some other solution here is mine and it includes 1 if:
Michał Targiel
May 28, 1:06 PMCORRECT:
public class Main {
I am constantly getting the following runtime errors:
Main.java:13: error: class, interface, or enum expected
public static void main(String[] args) {
Main.java:16: error: class, interface, or enum expected
int n = in.nextInt();
^
Main.java:17: error: class, interface, or enum expected
for(int i=0; i<n; i++){
^
Main.java:17: error: class, interface, or enum expected
for(int i=0; i<n; i++){
^
Main.java:17: error: class, interface, or enum expected
for(int i=0; i<n; i++){
^
Main.java:19: error: class, interface, or enum expected
int b= in.nextInt();
^
Main.java:20: error: class, interface, or enum expected
doStuff(a, b);
^
Main.java:21: error: class, interface, or enum expected
System.out.println("");
^
Main.java:22: error: class, interface, or enum expected
}
^
9 errors
Learneroo
Jul 6, 9:28 PM@Joshua, careful with
{}
. Reset the code and put back code in the method body.catypus
Sep 28, 11:14 AMWhat development app should I use to try this on my own? NetBeans? I've heard of that one...
Learneroo
Sep 28, 11:22 AMIn the next module, we suggest beginners use BlueJ to get started. Afterwards, you can use any of the main IDEs (Netbeans, Eclipse or IntelliJ)
Jaci Covington
Nov 10, 9:42 AMWhy do we have to put the print statement for the space on a separate line? I had no luck with (m, ' ')