Ladies and Gentelman,
Today we are going to learn how to create a multiplication (or Addition) table using Java.
First of all, copy the code below on your IntelliJ or paste on ChatGPT, to understand how it works. Usually if you paste a code on the AI, it can simulate if you order in your prompt. Ask it to simulate and run step by step letting you choose everything. That’s how I do to test a code, or game on Chat GPT.
The only reason the code does 1x1, 1x2, up to 1x10 is because the loop that determines the number to be multiplied is inside the first "for loop", which counts up to 10 for the first number to be used in the multiplication, conditioning what is printed to the multiplication (i * a).
To create the Addition table:
If I swap (i * a) with (i + a) and just change the X symbol to + in the printed output, I’ll get 1+1=2, and so on. It’s the same logic, but with a different symbol instead of multiplication.
Let me know in the comments if you have any question!
This was another great post by:
@xmauron3
”The Future is Awesome”
PORTUGUESE 🇵🇹 PORTUGUÊS 🇧🇷
Hoje vamos aprender como criar uma tabela de multiplicação (ou adição) usando Java.
O único motivo pelo qual o código faz 1x1, 1x2, até 1x10, é porque o loop que determina o número a ser multiplicado está dentro do primeiro loop for, que conta até 10 para o primeiro número a ser usado na multiplicação, condicionando o que é impresso à multiplicação (i * a).
Se eu trocar o (i * a) por (i + a) e apenas mudar o símbolo de X para + no que for impresso, eu terei 1+1=2, e assim por diante. É a mesma lógica, mas com outro símbolo no lugar da multiplicação.
Vejam isso no exemplo abaixo. Qualquer problema estou a disposição !
Esse foi outro ótimo post por:
@xmauron3
O Futuro é Incrível”
import java.sql.SQLOutput;
public class Main {
public static void main(String[] args) {
// multiplication table
for (int i = 1; i <= 10; i) {
System.out.println("--------------");
for (int a = 1; a <= 10; a) {
System.out.println(i + "+" + a + "=" + (i + a));
}
}
}
}