Write a program in Java to demonstrate use of this keyword. Check whether this can access the private members of the class or not.
// Write a program in Java to demonstrate use of this keyword. Check whether this can access the private members of the class or not.
public class Code10 {
private int x, y;
void valueGet(int x, int y) {
this.x = x;
this.y = y;
}
void display() {
int i, j, flag;
System.out.println("Prime between " + x + " to " + y);
System.out.println("------------------");
for (i = x; i <= y; i++) {
flag = 0;
for (j = 2; j <= i / 2; j++) {
if (i % j == 0) {
flag = 1;
break;
} } if (flag == 0) {
System.out.println(i);
} } } } class ThisDemoClass {
public static void main(String a[]) {
Code10 T = new Code10();
T.valueGet(5, 20);
T.display();
}
}
public class Code10 {
private int x, y;
void valueGet(int x, int y) {
this.x = x;
this.y = y;
}
void display() {
int i, j, flag;
System.out.println("Prime between " + x + " to " + y);
System.out.println("------------------");
for (i = x; i <= y; i++) {
flag = 0;
for (j = 2; j <= i / 2; j++) {
if (i % j == 0) {
flag = 1;
break;
} } if (flag == 0) {
System.out.println(i);
} } } } class ThisDemoClass {
public static void main(String a[]) {
Code10 T = new Code10();
T.valueGet(5, 20);
T.display();
}
}
Comments
Post a Comment