Monday 30 November 2015

Generate 10 Numbers and display the length of longest increasing order

//Generate 10 Numbers and display the length of longest increasing order

class P2
{
public static void main(String args[])
{
int inputnum=0,prevnum=0,counter=0,hcounter=0;
System.out.print("Random Numbers generated are: ");
for(int i=1;i<=10;i++)
{
inputnum=(int)(Math.random()*100);
System.out.print(""+inputnum+", ");
if(inputnum >= prevnum)
{
counter++;

if(counter>hcounter)
{
hcounter=counter;
}

}
else
{
counter=1;
}
prevnum=inputnum;
}
System.out.print("\nLength of longest increasing series is: "+(hcounter));
}
}

Saturday 28 November 2015

PROGRAM TO CALCULATE GENERATE A 5DIGIT NUMBER AND FINDING SUM OF ITS DIGIT

//Program to calculate generate a 5digit number and finding sum of its digit
class Sum
{
public static void main(String args[])
{
int num1,num=(int)(Math.random()*100000);
num1=num;
int sum=0,rem=0;
while(num!=0)
{
rem=num%10;
sum=sum+rem;
num=num/10;
}
System.out.println(“Sum of digits of “+num1+” is “+sum);
}
}

PROGRAM TO FIND GREATEST COMMOM FATOR OF TWO RANDOM NUMBERS

//program to find greatest common factor of two random numbers
class Gcd
{
public static void main(String args[])
{
int gcd=1,x=(int)(Math.random()*10);
int y=(int)(Math.random()*10);
int max;
if(x>y){max=x;}
else{max=y;}
for(int i=1;i<=max;i++)
{
if(x%i==0 && y%i==0)
{
gcd=i;
}
}
System.out.println(“Greatest common fator of “+x+” and “+y+” is “+gcd);
}
}

MYFIRST POST

Hi everyone! This is Tushar Attar and this is my first post on topjavaclass blog. I am going to post all the java program i will create for my future personal reference. Hope it will be helpful to me and also to other if my blog is indexed well my Google.
Thank you !!