|
Data and VariablesMethods are only half of a Java class. The other half is data. Consider the following generalization of the HelloWorld program:// This is the Hello Rusty program in Java class HelloRusty { public static void main (String args[]) { // You may feel free to replace "Rustywith your own name String name Rusty; /* Now let's say hello */ System.out.print("Hello ); System.out.println(name); } } Here, rather than saying hello to a rather generic world, we allow Java to say hello to a specific individual. We do this by creating a String variable called "nameand storing the value "Rustyin it. (You may, of course, have replaced Rusty with your own name.) Then we print out "Hello . Notice that we've switched here from System.out.println method to the similar System.out.print method. System.out.print is just like System.out.println except that it doesn't break the line after it's finished. Therefore when we reach the next line of code, the cursor is still located on the same line as the word "Helloand we're ready to print out the name. |
Bhopal news
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100