Posts

Palindrome Number

Java Program to check whether the entered Number entered by user is Palindrome or Not. package whileLoops; import java.util.Scanner; public class PalindromeNumber {     public static void main(String[] args)     {     Scanner input=new Scanner(System.in);         System.out.println("Enter a number:");         int n=input.nextInt();         int temp=n;         int reversed=0;         while(temp>0)         {         int lastDigit=temp%10;         reversed=reversed*10+lastDigit;         temp/=10;          }         if(reversed==n)            System.out.println("Yes ,"+n+" is a Palindrome Number");         else         System.out.println("No ,"+n+" is not a Palindrome Number");     } }

Sum of Digits

Java Program to find Sum of Digits of Number entered by user. package whileLoops; import java.util.Scanner; public class SumOfDigits { public static void main(String[] args)  { Scanner input=new Scanner(System.in); System.out.println("Enter a number:"); int n=input.nextInt(); int temp=n;     int sum=0; while(temp>0) { int lastDigit=temp%10;//lastDigit=2 temp/=10;//temp=54 sum+=lastDigit;//sum=2 } System.out.println("Sum of digits in "+n+" is "+sum); } }

Power

  Java Program to find X raised to the power Y, where X and Y are entered number by user. package loops; import java.util.Scanner; public class Power  { public static void main(String[] args)  { Scanner input=new Scanner(System.in); System.out.println("Enter two numbers:");//2 4 int a=input.nextInt();//x=2 int b=input.nextInt();//y=4 int result=1; for(int i=1;i<=b;i++) { result*=a; } System.out.println(a+" power "+b+" is "+result); } }

Decimal Number to Binary Number

Java Program to find Binary Number of the Decimal Number entered by user. package loops; import java.util.Scanner; public class DecimalToBinary { public static void main(String[] args)  { //Program to Convert the user Decimal Number to Binary Number Scanner input=new Scanner(System.in); System.out.println("Enter a number:"); int n=input.nextInt(); //n=200 System.out.print("Binary Number of "+n+" is "); int temp=n;//temp=200 for(int i=1073741824;i>0;i/=2)//i=0 //n=36 { if(i<=temp)//i=8 { System.out.print("1"); temp-=i;//temp=0 } else if(i<n) System.out.print("0"); } } }  

Calculator

Java Program to make a Simple Calculator. package conditionalStatements; import java.util.Scanner; class Calculator {     public static void main(String[] args)     {     Scanner input=new Scanner(System.in);     double num1,num2,result=0;     System.out.println("\t\t\tCalculator\n\nEnter First number:");     num1=input.nextDouble();     System.out.println("Enter Second number:");     num2=input.nextDouble();     System.out.println("Enter an Operator(+ - * / %) :");     input.nextLine();     char operator=input.nextLine().charAt(0);     switch(operator)     {     case '+':     result=num1+num2;     break;     case '-':     result=num1-num2;     break;     case '*':     result=num1*num2;     break;     case '/':     result=num1/num2;     break;     case '%':     result=num1%num2;     break;         default:     System.out.println("Invalid Ope

Simple Interest Calculator

Java Program to make a Simple Interest Calculator .   package practice; import java.util.Scanner; public class SimpleInterest  { public static void main(String[] args)  { Scanner scan=new Scanner(System.in); System.out.print("\t\t\tSimple Interest\n\nEnter the Principal(in INR):"); float principal=scan.nextFloat(); System.out.print("Enter the time(in year):"); int time=scan.nextInt(); System.out.print("Enter the rate of interest(out of 100%):"); float interest=scan.nextFloat(); System.out.println("Simple Interest is "+"\""+(principal*time*interest/100)+"\""+"\n\n\t\t\tTotal Amount is "+"\""+((principal*time*interest/100+principal))+"\""); } }     Keep Coding Keep Smiling :)

Prime or Not

Java Program to check whether the number entered by user is Prime or Not. package loops; import java.util.Scanner; public class Prime { public static void main(String[] args) {                  Scanner input=new Scanner(System.in);                     System.out.println("Enter a number:"); i nt n=input.nextInt(); String prime="Yes, a prime number";         for(int i=2;i*i<=n;i++)        {             if(n%i==0)                {                      prime="No, not a prime number";                     break;                }        }         if(n<2)                    prime="No, not a prime number";         S ystem.out.println(prime); } }     Keep Coding Keep Smiling :)