You are on page 1of 4

public class Disarium

{ int num,size;
Disarium(int nn)
{
num=nn;
size=0;
}
public void countDigit()
{
size=Integer.toString(num).length();
}
public int sumofDigits(int n,int p)
{
if (p==0)
return 0;
else
{
int d=n%10;
n/=10;
return (int)(Math.pow(d,p))+sumofDigits(n,p-1);
}
}
public void check()
{
if(num==sumofDigits(num,size))
{
System.out.println("Disarium");

}
else
{ System.out.println("not disarium");
}
}
public static void main(String args[])
{
Disarium obj= new Disarium(135);
obj.countDigit();
obj.check();
}
}

import java.util.*;
public class SumCombination //class name:SumCombination
{
int num;//variable to store the number whose sum combinations are to be found
public void accept()//method to accept the number from the keyboard
{
Scanner sc= new Scanner(System.in);
System.out.println("Enter the number");
num=sc.nextInt();
}
public void getComb()//method to print combinations
{
for(int i=1;i<=(num/2);i++)
{
int s=0,c;
for(c=i;s<num;c++)
{
s+=c;
}
if(s==num)// Checking if the present combination of consecutive natural
no.s gives the sum same as the given number
{
for(int k=i;k<c;k++)//Printing the combination
{
System.out.print(k+"\t");
}
System.out.println();
}
}
}
public static void main(String args[])//main method
{
SumCombination obj= new SumCombination();
obj.accept();
obj.getComb();
}
}

import java.util.*;
public class Dategen
{
String n;
public void input()
{
Scanner sc= new Scanner(System.in);
do
{
System.out.println("Enter the number format of date");
n=sc.next();
}while(n.length()!=6);
}
public void getDate()
{
int nd[]={31,28,31,30,31,30,31,31,30,31,30,31};
String
mo[]={"January","February","March","April","May","June","July","August","September"
,"October","November","December"};
int dd=Integer.parseInt(n.substring(0,2));
int mm=Integer.parseInt(n.substring(2,4));
int yy=Integer.parseInt(n.substring(4));
if(isLeap(yy))
{
nd[1]=29;
}
if(mm>=1&&mm<=12)
{
if(dd>=1&&dd<=nd[mm-1])
{
String pos= getPos(dd);
System.out.println(dd+pos+" "+mo[mm-1]+", "+yy);
System.out.println("VALID DATE");
}
else
{
System.out.println("INVALID DATE");
}
}
else
{
System.out.println("INVALID DATE");
}
}
public boolean isLeap(int y)
{
boolean b= false;
if(y%4==0)
{
if(y%100==0)
{
if(y%400==0)
{
b=true;
}
}
else
{
b=true;
}
}
return b;
}
public String getPos(int n)
{
String s="";
switch(n)
{
case 1:
case 21:
case 31:
s="st";
break;
case 2:
case 22:
s="nd";
break;
case 3:
case 23:
s="rd";
break;
default:
s="th";
break;
}
return s;
}
public static void main(String args[])
{
Dategen obj= new Dategen();
obj.input();
obj.getDate();
}
}

You might also like