TP0
TP0
Computer Science
2nd A. Ing.
It should be noted that the instruction "System.out.println ("Hello world!");" allows you to display a
message on the screen followed by a line break, which is similar to "printf" in C language. The
function "System.out.print("msg")" allows you to display a message without a line break.
Exercise 1: Input/output, interaction with the user in console mode
Write a program that asks the user for their name and displays a personalized greeting.
Write a program that prompts the user for two numbers and displays the sum of those numbers.
Exercise 2:
Deduce theoretically (on paper) the result of the following code. Then compare your answer to
the result from its compilation and execution.
int z=x+y;
z-= 5;// Equivalent to z = z - 5;
double d= 4.5;
int i= 2;
d/=i;// Equivalent to d = d / i;
String text1="Hello";
String text2="World";
public classExampleOperations{
d= (int) (b+=a);
System.out.println("A : a="+a+" b="+b+" c="+c+" d="+d);
a=b=c= 5;
a*=b+=c;
System.out.println("B: a="+a+" b="+b+" c="+c);
c=a<b?a++ :b--;
System.out.println("C: a="+a+" b="+b+" c="+c);
c=a>b?a-- :b++;
System.out.println("D: a="+a+" b="+b+" c="+c);
}
}