Posts

Showing posts from March, 2022

Taking input from the user in java

 package mypro;   import java.util.Scanner; //public class MyOwn{ // // static void lakshman1() { //     System.out.println("I just got executed!"); //   } //} public class TakingInputFromTheUser { static void lakshman() {       System.out.println("I just got executed!");     }       public static void main(String[] args) {      Scanner obj = new Scanner(System.in);      System.out.println("Enter the value of a : ");      String a = obj.nextLine();      System.out.println("Enter the value of b : ");      int b = obj.nextInt();      System.out.println("The sum of a and b is : "+(a+b));           lakshman();               }    }

Checking that given number is automorphic or not by lakshmankablog

 package mypro; import java.util.Scanner; public class AutoMorphicNumber { public static void main(String[] args) { Scanner obj= new Scanner(System.in); System.out.println("Enter the number for checking is an automorphic or not "); int n= obj.nextInt(); int n2,len=0,len2,rem,rem1,rev; int restn=n; n2= n*n; while(n>0) { len++; n = n/10; } // System.out.println(len); len2=len; rev=0; for(int i= 0; i<len; i++) { rem = n2 % 10;  rev= rev*10+rem; n2 = n2/10; } // System.out.println(rev); int revofrev = 0; for(int j=0; j<len2; j++) { rem1= rev%10;  revofrev = revofrev*10+rem1; rev = rev/10; } // System.out.println(revofrev); if(restn==revofrev) { System.out.println("The number "+restn+" "+" is automorphic "); } else { System.out.println("The number is not  automorphic "); } } }

Printing the ascii value of each and every character in java

 package mypro; public class AsciiValuePrinting { public static void main(String[] args) { int r1=1; int r2=255; for(int i=r1; i<=r2; i++) { char ch1=(char) i; System.out.println(i +" == "+ch1); } } }

CHECKING THE NUMBER IS PETERSON OR NOT IN JAVA

 package mypro; import java.util.Scanner; public class PetersonBetweenRang { public static int fact(int n) {   int fact=1;   for(int i= 1; i<=n;i++) {   fact= fact*i;   }      return fact; } public static void main(String[] args) { System.out.println("Enter the range r1 and r2 to check all the number they are or not "); Scanner obj = new Scanner(System.in); int r1 = obj.nextInt(); int r2 = obj.nextInt(); for(int i=r1; i<=r2; i++) { int n=i; int restn=n,rem;int add=0; while(n>0) { rem=n%10; add= add+fact(rem);   n= n/10; } // System.out.println(add); if(restn==add) { System.out.println("The numbe "+ restn+" is peterson "); } else { System.out.println(" The number "+ restn+" is not peterson"); } } } }

CHECKING THAT NUMBER IS SUNNY OR NOT IN JAVA

 package mypro; import java.util.Scanner; public class SunnyNumBetRange { public static void main(String[] args) { System.out.println("Enter the range r1 and r2 to check all the number they are sunny or not "); Scanner obj = new Scanner(System.in); int r1 = obj.nextInt(); int r2 = obj.nextInt(); for(int i=r1; i<=r2; i++) { int n=i,rem ,nsq=i*i,add=0; while(nsq>0) { rem=nsq%10; add=add+rem; nsq=nsq/10; } if(add==n) { System.out.println("The number "+ n+" sunny"); } else { System.out.println("The number "+ n+" is not sunny");} } } }

TAKING THE NUMBERS FROM THE USER AND GIVING THE LCM OF THESE NUMBERS

 package mypro; import java.util.Scanner; public class LCMOFUSERENTERNUMBER { public static void main(String[] args) {   System.out.println("How many numbers's LCM you wanna know, Max length is 6 "); Scanner obj = new Scanner(System.in); int n= obj.nextInt(); if(n>6) { System.out.println("Length is over enter again"); System.exit(0); }   int i; switch(n) { case 1: System.out.println("Paagal hai kya ?"); break; case 2: System.out.println("Enter the numbers "); int a= obj.nextInt(); int b= obj.nextInt(); for(i=b; i<=a*b; i++) { if(i%a==0 && i%b==0) { System.out.println("Lcm is  "+i); break; } } case 3: System.out.println("Enter the numbers "); int a1= obj.nextInt(); int b1= obj.nextInt(); int c1= obj.nextInt(); for(i=b1; i<=a1*b1*c1; i++) { if(i%a1==0 && i%b1==0 && i%c1==0) {...

finding the fibonacci series between the ranges each and every series 5-8 like this in c language

 #include<conio.h> #include<stdio.h> int main() {      int r1=5,r2=7,a,b,c;      for(int  i= r1; i<=r2; i++){          printf("The fibonacci series of %d :: ",i);          a=0,b=1;           printf("%d %d",a,b);         for(int j=2; j<i; j++){             c=a+b;             printf(" %d",c);             a=b;             b=c;         }         printf("\n");               }      return 0; }