Saturday, June 29, 2019

Mersenne Number | Programming | Eclipse JAVA | Follow on Youtube for more




import java.util.*;
public class mersenne_number
{
static boolean prime_check(double n)
{
int count = 0;
for(int i=1;i<n;i++)
{
if(n%i==0)
count++;
}
if(count==1)
return true;
else
return false;
}
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter till where mersenne number is to be generated");
int n = sc.nextInt();
double a[] = new double[100];// storing the answers
int count = 0;
for(int i=2;i<n;i++)
{
double number = Math.pow(2, i)-1; //   2^k-1
if(number<=n)
{
boolean result = prime_check(number);
if(result==true)
{
a[count++]  =  number;
}
}
else
{
break;
}
}
if(count!=0)
{
System.out.println("The Mersenne number are as follows :");
for(int i=0;i<count;i++)
{
System.out.println(a[i]);
}
}
else
System.out.println("There are no mersenne number");
}
}
/*
Mersenne Prime is a prime number that is one less than a power of two. In other words,
any prime is Mersenne Prime if it is of the form 2^k-1 where k is an integer greater than
or equal to 2. First few Mersenne Primes are 3, 7, 31 and 127.

The task is print all Mersenne Primes smaller than an input positive integer n.
Examples:

Input: 10
Output: 3 7
3 and 7 are prime numbers smaller than or
equal to 10 and are of the form 2^k-1

Input: 100
Output: 3 7 31
 */

Friday, June 28, 2019

Pronic Number | Programming | Eclipse JAVA | Follow on Youtube for more




import java.util.*;
class Pronic_Number
{
    public static void main1(String []args)
    {
        int num,count=0,d;
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter the number");
        num=sc.nextInt();
        for( int i=1;i<(num/2);i++)//6
        {
            d=i*(i+1);
            if(d==num)
            {
            count=count+1;
            break;
             }
            else
            d=0;
        }
        if(count>0)
        System.out.println(num+" is a pronic number");
        else
        System.out.println(num+" is not a pronic number");
    }
}
/*
 A pronic number is a something which is a product of 2 consecutive numbers.
 
Input  : 6
Output : Pronic Number
Explanation: 6 = 2 * 3 i.e 6 is a product
of two consecutive integers 2 and 3.

Input :56
Output :Pronic Number
Explanation: 56 = 7 * 8 i.e 56 is a product
of two consecutive integers 7 and 8.

Input  : 8
Output : Not a Pronic Number
Explanation: 8 = 2 * 4 i.e 8 is a product of
2 and 4 which are not consecutive integers.
*/


Harshad Number | Programming | Eclipse JAVA | Follow on Youtube for more






import java.util.*;
// Harshad number is also called niven number
public class harshad_number
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number to be checked");
int n  = sc.nextInt();
int n1 = n;
int sum = 0;
while(n1!=0)
{
int rem  = n1%10;
sum  = sum + rem;
n1 = n1/10;
}
if(n%sum==0)
{
System.out.println(n+" is a harshad number");
}
else
{
System.out.println(n+" is not a harshad number");
}
}
}
/*
Input: 3
Output: 3 is a Harshad Number

Input: 18
Output: 18 is a Harshad Number

Input: 15   
Output: 15 is not a Harshad Number


54       9
*/

Duck Number | Programming | Eclipse JAVA | Follow on Youtube for more




Code:
import java.util.Scanner;
public class duck_number
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number to be checked");
String s = sc.next();
char c = s.charAt(0);
if(c=='0')
System.out.println(s+" is not a duck number");
else
{
int count = 0;
for(int i=1;i<s.length();i++)
{
c = s.charAt(i);
if(c=='0')
count++;
}
if(count>0)
System.out.println(s+" is a duck number");
else
System.out.println(s+" is not a duck number");
}
}
}
/*
 Input : 707069
Output : It is a duck number.
Explanation: 707069 does not contains zeros at the beginning.

Input : 02364
Output : It is not a duck number.
Explanation: in 02364 there is a zero at the beginning of the number.
 */

Data Types in JAVA | Understanding Variables | UNICODE | LIKE SHARE AND SUBSCRIBE |


This video explains about primitive and non primitive data types in java.
It explains all 8 types of data types:
the arithmetic types:

A. The integral types:
1. byte
2. short
3. int
4. long

B. The floating-point types:
5. float
6. double

C. boolean, the type whose values are either true or false

D. char, the character type whose values are 16-bit Unicode characters

It also explains about Local, Global and Static variable type.

Downloading and Installing Eclipse | Like Share Subscribe|

This video shows you complete process of how to download and install Eclipse.
 It works everytime.

Eclipse Download:  https://www.eclipse.org/downloads/

Please Like Share and Subscribe..


Running program in Command Prompt using Text File | Follow Youtube for More |

This video shows you how you can run simple java program using text file and command prompt. It also teaches you basic commands of command prompt.



Java Environment Setup(100% working)| Running text files from Command Prompt| Susbscribe to Youtube for more

The video shows you how to setup java path, so that you can run java program through command prompt that is using a text file.

Link for Jdk : https://www.oracle.com/technetwork/java/javase/downloads/jdk11-downloads-5066655.html


Disarium Number | Programming | Eclipse JAVA | Follow on Youtube for more



import java.util.*;
public class disarium_number
{
static boolean check(int n1)
{
//Reversing the number
String s = Integer.toString(n1),s2 = "";
//Reverse loop
for(int i=0;i<s.length();i++)
{
char c = s.charAt(i);
s2 = c+s2;// reverse number in string format
}
int n = Integer.parseInt(s2);
double sum = 0;
int power = 1;
//checking the number
while(n!=0)//531
{
int rem = n%10;
sum = sum+Math.pow(rem,power);
n = n/10;
power++;
}
System.out.println("The sum is "+sum+" and Original Number is "+n1);
if(sum==n1)
return true;
else
return false;
}
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
//taking user input
System.out.println("Enter the number to be checked");
int n = sc.nextInt();
//sending the number to be checked
boolean b = check(n);
if(b==true)
System.out.println(n+" is a disarium number");
else
System.out.println(n+" is not a disarium number");
sc.close();
}
}

/*
Input   : n = 135
Output  : Yes
1^1 + 3^2 + 5^3 = 135
Therefore, 135 is a Disarium number

Input   : n = 89
Output  : Yes
8^1+9^2 = 89
Therefore, 89 is a Disarium number

Input   : n = 80
Output  : No
8^1 + 0^2 = 8
 */

Automorphic Number Programming | In JAVA | Eclipse |



import java.util.Scanner;
public class automorphic_number
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number to be checked ");
int n  = sc.nextInt();
int square  = n*n;     
System.out.println(square);
String s = Integer.toString(n);
int l = s.length();           
double power = Math.pow(10, l);
double rem = square%power;
if(rem==n)
System.out.println(n+" is an automorphic number");
else
System.out.println(n+" is not an automorphic number");
sc.close();
}
}
/*
Input  : N = 76
Output : Automorphic
Explanation: As 76*76 = 5776

Input  : N = 25
Output : Automorphic
As 25*25 = 625

Input : N = 7
Output : Not Automorphic
As 7*7 = 49
 5
 25

 */

Kaprekar Number | Programming | Eclipse JAVA | Follow on Youtube for more

Code:
import java.util.*;
public class kaprekar_number
{
static int check(int square,int n)
{
String s = Integer.toString(square);
int l = s.length();
if(l%2==0) // when square has even digits
{
String s1 = s.substring(0,l/2);//20
int n1 = Integer.parseInt(s1);
String s2 =s.substring(l/2,l); //25
int n2 = Integer.parseInt(s2);
System.out.println(s1+"  "+s2);
if((n1+n2)==n&& n1>0 &&n2>0)
return 1;
}
else // When the square has odd digits
{
String s1 = s.substring(0,l/2+1);
int n1 = Integer.parseInt(s1);
String s2 =s.substring(l/2+1,l);
int n2 = Integer.parseInt(s2);
System.out.println(s1+"  "+s2);
if((n1+n2)==n && n1>0 &&n2>0)
return 1;
String s3 = s.substring(0,l/2);
int n3 = Integer.parseInt(s3);
String s4 =s.substring(l/2,l);
int n4 = Integer.parseInt(s4);
System.out.println(s3+"  "+s4);
if(((n3+n4)==n)&& n3>0 &&n4>0)
return 1;
}

return 0;
}
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number to be checked");
int n = sc.nextInt();
int square = n*n;
System.out.println(square);
int result  = check(square,n);
if(result ==1)
System.out.println(n+" is a kaprekar number");
else
System.out.println(n+" is not a kaprekar number");
sc.close();
}
}


/*
Input :  n = 45
Output : Yes
Explanation : 45^2 = 2025 and 20 + 25 is 45

Input : n = 13
Output : No
Explanation : 13^2 = 169. Neither 16 + 9 nor 1 + 69 is equal to 13

Input  : n = 297
Output : Yes
Explanation:  297^2 = 88209 and 88 + 209 is 297 and 882+09 = 891

Input  : n = 10
Output : No
Explanation:  10^2 = 100. It is not a Kaprekar number even if
sum of 10 + 0 is 10. This is because of the condition that
none of the parts should have value 0.
 */

ICSE COMPUTER SCIENCE SPECIMEN PAPER | QUESTION 7 | PLEASE DO WATCH THE VIDEO

  import  java.util.*; class icse_specimen_1 {     public static void main(String[] args)     {         Scanner sc1 = new Scanner(System.in)...