"Há muito tempo, os computadores só podiam exibir texto. Os programas exibiam dados na tela depois de receber entrada do teclado. Isso é chamado de 'interface do usuário do console' ou simplesmente 'console'. Uma interface de janela é uma alternativa ao console. Com Neste tipo de interface, o usuário interage com o programa através de uma ou mais janelas. Como estamos aprendendo a programar, vamos começar trabalhando com o console."

"Tudo bem."

"O texto é exibido no console (tela) consecutivamente, linha por linha. O texto é inserido usando o teclado. Para evitar erros, a entrada do teclado é exibida na tela. Às vezes parece que o usuário humano e o programa estão se revezando escrevendo coisas na tela. "

"Você pode usar o método System.out.print () para exibir texto na tela. Esse método simplesmente exibe o texto, enquanto System.out.println () exibe o texto e move o cursor para a próxima linha."

Código Resultado
System.out.print("Rain");
System.out.print("In");
System.out.print("Spain");
RainInSpain
System.out.print("Rain");
System.out.println("In");
System.out.print("Spain");
ChuvaNa
Espanha
System.out.println("Rain");
System.out.println("In");
System.out.println("Spain");
Chuva
na
Espanha

"Para manter pedaços de texto separados, precisamos adicionar um espaço. Por exemplo:"

Código Resultado
int a = 5, b = 6;
System.out.print(a);
System.out.print(b);
56
int a = 5, b = 6;
System.out.print(" " + a + " " + b);
 5 6
int a = 5, b = 6;
System.out.print("The sum is " + (a + b));
The sum is 11

"Entendi"

"Isso permite exibir qualquer coisa na tela: todos os objetos Java podem ser transformados em uma string. Todas as classes Java derivam da classe Object, que possui o método toString(). Esse método é chamado quando você deseja transformar um objeto em um corda."

Código Descrição
Cat cat = new Cat("Oscar");
System.out.println("The cat is " + cat);
Esses três exemplos são equivalentes.
Cat cat = new Cat("Oscar");
System.out.println("The cat is " + cat.toString());
Cat cat = new Cat("Oscar");
String catText = cat.toString();
System.out.println("The cat is " + catText);
3
Tarefa
Java Syntax,  nível 3lição 3
Bloqueado
Display right away
Programming isn't always difficult. Sometimes you need to do simple tasks. And the more similar tasks you have to do, the more you want to automate them. Let's implement one more method. Ultimately, objects without methods don't do anything. We'll pass the string s to the method, which will then display it on the screen.

"Mas meu programa exibiu ' O gato é com.codegym.lesson3.Cat@1fb8ee3 '. O que diabos isso quer dizer?"

"O método toString() padrão da classe Object retorna uma string que consiste no nome da classe e no endereço de memória do objeto (em formato hexadecimal)."

"Uh-huh. E que bem poderia vir de tal método?"

"Você pode escrever sua própria implementação de toString() em sua classe. Esse é o método que será chamado."

"Sério? Tudo bem."

"Aqui estão algumas tarefas de Diego."

3
Tarefa
Java Syntax,  nível 3lição 3
Bloqueado
Currency exchange
Loan sharking, sales, banking: do you have a backup plan if programming doesn't work out? No? In that case, let's help traders and financiers with our top-notch programs. First, we'll organize a currency exchange: write a program that converts euros to dollars at a given exchange rate.
3
Tarefa
Java Syntax,  nível 3lição 3
Bloqueado
Task with percentages
If you weren't afraid of problems with percentages in school, then this problem won't scare you either. But if you do suddenly find yourself afraid, it's time to face your fear and realize that this is actually a simple and pleasant topic. Let's implement a method that increases the passed integer by 10 percent.
1
Tarefa
Java Syntax,  nível 3lição 3
Bloqueado
Code entry
Your attention, please! Now recruiting code entry personnel for CodeGym. So turn up your focus, let your fingers relax, read the code, and then... type it into the appropriate box. Code entry is far from a useless exercise, though it might seem so at first glance: it allows a beginner to get used to and remember syntax (modern IDEs seldom make this possible).