New course! Every coder should learn Generative AI!
Try a free lesson+ 1
Why does this work??
import java.util.Scanner; public class multiplication { public static void main(String[]args){ Scanner in = new Scanner(System.in); System.out.println("Enter a number"); int number1 = in.nextInt(); for (int i=0; i<10; i++){ System.out.println(number1+ "x" + (i+1) + "="+(number1 * (i+1))); in.close(); } } } can someone explain why it prints up to * 10 instead of up to * 9? and can someone break this down (in simple english for dummies)
8 Answers
+ 3
Let me then tell you one thing.
I know c++,HTML,css only.
But I know all them by heart. Others are similar And I always try to work out questions by some common logic. You are learning java go for it you can after that do other languages easily only a change of syntax is major difference.
By the way I really don't know java(I know I have completed the course) And I worked this one out by c++ logic.
+ 2
see in the code in loop it is (i+1) so it starts from
0+1=1//I=0
2
3
4
5
6
7
8
9//i=8
10//i=9
+ 2
first one closes
(I+1)
second one closes
(number 1*(I+1))
third one closes system.out.printin.
+ 2
yes only logic are common across all languages.
But c++ and java are even more closer.
they have same way of looping
+ 1
ok one last question why is there 3 parenthesis to the right of (i+1)));
+ 1
oooh ok thanks very much I'm really new to coding started about 3 weeks ago
+ 1
oh cool thats nice to know so does java and other languages have alot in common with each other?
+ 1
oh kk thx for the info