P
P
PRAIT2019-05-12 10:17:06
Java
PRAIT, 2019-05-12 10:17:06

Why are numbers and symbols added in the program?

There is a code

package testproject;
import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
    try(Scanner input = new Scanner(System.in)) {
      String name, surname;
      int year, years;
      System.out.println("Привет, как тебя зовут?");
      name = input.nextLine();
      System.out.println("Очень приятно "+name+" а у тебя есть фамилия?");
      surname = input.nextLine();
      System.out.println("Мне очень приятно с тобой познакомиться "+name+" "
              + ""+surname+" а меня зовут Тоша, в каком году ты родился?");
      year = input.nextInt();
      System.out.println("Я так и предполагал! "+name+" если не трудно напомни "
              + "мне какой сейчас год?");
      years = input.nextInt();
      System.out.println("Так, так, так.. Если ты "+year+" года, а сейчас "
              + ""+years+" год, получается тебе "+(year-years)+" верно?");
    }
  }
}

When compiled, it produces this
Hello what is your name?
Nem
Very nice Nem do you have a surname?
Yum
It's a pleasure to meet you Nem Yum and my name is Tosha, what year were you born?
1996
I thought so! If it's not difficult, remind me what year it is?
2019
So, so, so.. If you are 1996, and now 2019, it turns out you are -23 right?
ASSEMBLY COMPLETED SUCCESSFULLY (total time: 26 seconds)

I can't figure out where the character "-" comes from before 23, please explain!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kirill Romanov, 2019-05-12
@PRAIT

1996 - 2019 = -23

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question