Multiplication (or Addition) Table Using a "For Loop" [ENG/PT]
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:
”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:
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));
}
}
}
}
Leave Multiplication (or Addition) Table Using a "For Loop" [ENG/PT] to:
Read more #coding posts
Best Posts From xmauron
We have not curated any of xmauron3's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.
More Posts From xmauron
- Beautiful Summer Day
- A Psychedelic Vacuum - CCC's Street Art Contest (Round #228)
- My Actifit Report Card: December 22 2024
- The Power of Inflation in Brazil
- Privacy is Back! 🕵️[ENG/PT]
- Electric FM 📻 NY Radio [ENG/PT/ESP]
- The War on Drugs in Brazil ⚖️ Part. 1 👮♂️[ENG/PT/ESP]
- Blueberry Strawberry Cocktail 🍹 [ENG/PT/ESP]
- My Actifit Report Card: September 13 2024
- My Actifit Report Card: September 11 2024
- Ecency Translation Progress 🇵🇹 Portuguese 🇧🇷 [ENG/PT/ESP]
- Space Music 🌞 Music Tribe
- My Actifit Report Card: September 9 2024
- Multiplication (or Addition) Table Using a "For Loop" [ENG/PT]
- For Loop Class 👨🏫 We Learn Fast 💻 [ENG/PT/ESP]
- Mastering the Basics of Java 👨💻 [ENG/PT]
- My Actifit Report Card: August 23 2024
- Java Classes 🧑💻 It’s Great to Learn!
- Starting to Learn Java
- Ecency 🇧🇷 Portuguese 🇵🇹 Translation Progress [ENG/PT]