Multiplication (or Addition) Table Using a "For Loop" [ENG/PT]

in #coding2 months ago (edited)

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)); } } } }

Sort:  

Sending love and curation Ecency vote. keep giving the best

Please vote for Ecency proposal👇
https://ecency.com/proposals?filter=team

Thanks!

Obrigado por promover a Língua Portuguesa em suas postagens.

Vamos seguir fortalecendo a comunidade lusófona dentro da Hive.

Metade das recompensas dessa resposta serão destinadas ao autor do post.

Vote no @perfilbrasil para Testemunha Hive.

Valeu!

Congratulations @xmauron3! You have completed the following achievement on the Hive blockchain And have been rewarded with New badge(s)

You distributed more than 99000 upvotes.
Your next target is to reach 100000 upvotes.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

Check out our last posts:

The countdown to HiveFest⁹ is one week away - Join us and get your exclusive badge!
Our Hive Power Delegations to the August PUM Winners
Feedback from the September Hive Power Up Day

Nice!

Getting closer to the 100k upvotes. Awesome work @xmauron3