source file name: Div6or8Demo.java
import java.io.*;
class A
{
int y;
public A(int n)
{
y=n;
}
public void disp()
{
int d=1;
while(d<=y)
{
if(d%6==0 || d%8==0)
System.out.println(d);
d++;
}
}
}
class Div6or8Demo
{
public static void main(String as[])
{
int n=1;
System.out.println("enter value: ");
try
{
DataInputStream dis=new DataInputStream(System.in);
String s=dis.readLine();
n=Integer.parseInt(s);
}
catch(Exception e)
{
System.out.println(e);
}
A ob=new A(n);
System.out.println("divisible by 6 or 8 : ");
ob.disp();
}
}
output:
D:\JavaPrograms\Constructors>javac Div6or8Demo.java
D:\JavaPrograms\Constructors>java Div6or8Demo
enter value:
60
divisible by 6 or 8 :
6
8
12
16
18
24
30
32
36
40
42
48
54
56
60
0 Comments
Post a Comment