Biblioteca Java - Blame information for rev 39
Subversion Repositories:
Rev | Author | Line No. | Line |
---|---|---|---|
39 | mihai | 1 | package introducere.java.controlflow; |
4 | mihai | 2 | |
3 | /** | ||
4 | * Exemplify if-else structures | ||
5 | */ | ||
6 | public class IfElse { | ||
7 | |||
8 | static int getMaxValue(int a, int b){ | ||
9 | int tmp; | ||
10 | if(a>=b) | ||
11 | return a; | ||
12 | else | ||
13 | return b; | ||
14 | } | ||
15 | |||
16 | static int getMaxValue2(int a, int b){ | ||
17 | int tmp; | ||
18 | if(a>=b) | ||
19 | tmp = a; | ||
20 | else | ||
21 | tmp = b; | ||
22 | return tmp; | ||
23 | } | ||
24 | |||
25 | static void testTemperature(int temp){ | ||
26 | if(temp<5) | ||
27 | System.out.println("Low temperature"); | ||
28 | else if(temp>=5&&temp<24) | ||
29 | System.out.println("Normal temperature"); | ||
30 | else | ||
31 | System.out.println("High temperature"); | ||
32 | } | ||
33 | |||
34 | public static void main(String[] args) { | ||
35 | |||
36 | int x = 10, y=34; | ||
37 | System.err.println("Compare "+x+" with "+y+" .Max value is "+getMaxValue(x,y)); | ||
38 | |||
39 | x = x*10; | ||
40 | y = x-y; | ||
41 | System.err.println("Compare "+x+" with "+y+" .Max value is "+getMaxValue2(x,y)); | ||
42 | |||
43 | |||
44 | int temperature = 34; | ||
45 | testTemperature(temperature); | ||
46 | } | ||
47 | } |