forked from navinreddy20/Javacode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
6.7 Enhanched for loop.java
63 lines (49 loc) · 946 Bytes
/
6.7 Enhanched for loop.java
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
class Student
{
int rollno;
String name;
int marks;
}
public class Demo {
public static void main(String[] args)
{
Student s1=new Student();
s1.rollno=1;
s1.name="Navin";
s1.marks=88;
Student s2=new Student();
s2.rollno=2;
s2.name="Harsh";
s2.marks=67;
Student s3=new Student();
s3.rollno=3;
s3.name="Kiran";
s3.marks=97;
System.out.println(s1.name + ":"+ s1.marks);
Student students[]=new Student[3];
students[0]=s1;
students[1]=s2;
students[2]=s3;
// for(int i=0;i<students.length;i++)
// {
// System.out.println(students[i].name+":"+students[i].marks);
// }
for(Student stud: students)
{
System.out.println(stud.name +":"+stud);
}
int nums[]=new int[4];
nums[0]=4;
nums[1]=8;
nums[2]=3;
nums[3]=9;
// for (int i=0;i<nums/length;i++)
// {
// System.out.println(nums[i]);
// }
for(int n: nums)
{
System.out.println(n);
}
}
}