Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Anisha_AbundantNumber.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import java.util.Scanner;
public class Anisha_AbundantNumber {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number: ");
int num = sc.nextInt();
sc.close();

int sum = 0;

for (int i = 1; i <= num / 2; i++) {
if (num % i == 0) {
sum += i;
}
}

if (sum > num) {
System.out.println("It's an Abundant Number");
} else {
System.out.println("Not an Abundant Number");
}
}
}
52 changes: 52 additions & 0 deletions Anisha_AddTwoFractions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import java.util.Scanner;

public class Anisha_AddTwoFractions {

// Method to find HCF (GCD)
static int findHCF(int a, int b) {
while (b != 0) {
int temp = b;
b = a % b;
a = temp;
}
return a;
}

// Method to find LCM
static int findLCM(int a, int b) {
return (a * b) / findHCF(a, b);
}

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

// Input first fraction
System.out.print("Enter numerator of first fraction: ");
int n1 = sc.nextInt();
System.out.print("Enter denominator of first fraction: ");
int d1 = sc.nextInt();

// Input second fraction
System.out.print("Enter numerator of second fraction: ");
int n2 = sc.nextInt();
System.out.print("Enter denominator of second fraction: ");
int d2 = sc.nextInt();

// Find LCM of denominators
int lcm = findLCM(d1, d2);

// Convert fractions and add
int sumNumerator = (n1 * (lcm / d1)) + (n2 * (lcm / d2));
int sumDenominator = lcm;

// Simplify the fraction
int hcf = findHCF(sumNumerator, sumDenominator);
sumNumerator /= hcf;
sumDenominator /= hcf;

// Output result
System.out.println("Sum of fractions = " + sumNumerator + "/" + sumDenominator);

sc.close();
}
}
10 changes: 10 additions & 0 deletions Anisha_AreaOfCircle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import java.util.Scanner;
public class Anisha_AreaOfCircle {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double r = sc.nextDouble();
double area = 3.14*r*r;
System.out.println("Radius od circle is: "+area);
sc.close();
}
}
35 changes: 35 additions & 0 deletions Anisha_ArmstrongNumber.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import java.util.Scanner;
public class Anisha_ArmstrongNumber {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number: ");
int num = sc.nextInt();
sc.close();
int len = count(num);
if(armstrong(num,len)){
System.out.println(num + " is an armstrong");
}
else{
System.out.println(num + " is not an armstrong");
}

}
static int count (int x){
int c = 0;
while(x>0){
c++;
x = x/10;
}
return c;
}
static boolean armstrong(int num,int len){
int sum =0;
int temp = num;
while(temp!=0){
int ld = temp%10;
sum = sum + (int)Math.pow(ld,len);
temp/=10;
};
return sum==num;
}
}
36 changes: 36 additions & 0 deletions Anisha_ArmstrongNumberinGivenRange.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import java.util.Scanner;
public class Anisha_ArmstrongNumberinGivenRange {

static int count(int n){
int c =0;
while(n>0){
c++;
n = n/10;
}
return c;
}
static boolean isArmStrong(int num){
int len = count(num);
int temp = num;
int sum = 0;
while(temp>0){
int di = temp%10;
sum = sum + (int) Math.pow(di,len);
temp/=10;
}
return sum==num;
}

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the range: ");
int low = sc.nextInt();
int high = sc.nextInt();
for(int i = low;i<=high;i++){
if(isArmStrong(i)){
System.out.print(i + " ");
}
}
sc.close();
}
}
20 changes: 20 additions & 0 deletions Anisha_AutomorphicNumber.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import java.util.Scanner;
public class Anisha_AutomorphicNumber {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number: ");
int n = sc.nextInt();
sc.close();
int sq = n*n;
String num = String.valueOf(n);
String square = String.valueOf(sq);
if(square.endsWith(num)){
System.out.println("Yes, it's an AUtomorphic Number");

}
else{
System.out.println("No it's not an Automorphic Number");
}

}
}
36 changes: 36 additions & 0 deletions Anisha_BinaryToOctal.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import java.util.Scanner;

public class Anisha_BinaryToOctal {
public static void main(String[] args) {

Scanner sc = new Scanner(System.in);
System.out.print("Enter a Binary Number: ");
String binary = sc.next();
sc.close();

// Step 1: Binary to Decimal
int decimal = 0;
int power = 0;

for (int i = binary.length() - 1; i >= 0; i--) {
int digit = binary.charAt(i) - '0';
decimal += digit * Math.pow(2, power);
power++;
}

// Step 2: Decimal to Octal
int[] octal = new int[32];
int index = 0;

while (decimal > 0) {
octal[index] = decimal % 8;
decimal = decimal / 8;
index++;
}

System.out.print("Octal value = ");
for (int i = index - 1; i >= 0; i--) {
System.out.print(octal[i]);
}
}
}
23 changes: 23 additions & 0 deletions Anisha_BinearyToDecimal.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import java.util.Scanner;

public class Anisha_BinearyToDecimal {
public static void main(String[] args) {

Scanner sc = new Scanner(System.in);
System.out.print("Enter a binary number: ");
int binary = sc.nextInt();
sc.close();

int decimal = 0;
int power = 0;

while (binary > 0) {
int digit = binary % 10;
decimal = decimal + digit * (int)Math.pow(2, power);
binary = binary / 10;
power++;
}

System.out.println("Decimal equivalent: " + decimal);
}
}
31 changes: 31 additions & 0 deletions Anisha_CountNumberOfDigitsInInteger.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import java.util.Scanner;

public class Anisha_CountNumberOfDigitsInInteger {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.print("Enter an integer: ");
int num = sc.nextInt();

int count = 0;
int temp = num;

if (temp == 0) {
count = 1;
} else {
if (temp < 0) {
temp = -temp; // convert negative to positive
}

while (temp != 0) {
temp = temp / 10;
count++;
}
}

System.out.println("Number of digits = " + count);
sc.close();
}
}
45 changes: 45 additions & 0 deletions Anisha_CountNumbersWithExactlyXDivisors.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import java.util.Scanner;
public class Anisha_CountNumbersWithExactlyXDivisors {
static int countDivisors(int num) {
int count = 0;

for (int i = 1; i <= num; i++) {
if (num % i == 0) {
count++;
}
}
return count;
}

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.print("Enter starting range: ");
int start = sc.nextInt();

System.out.print("Enter ending range: ");
int end = sc.nextInt();

System.out.print("Enter X (number of divisors): ");
int x = sc.nextInt();

int totalNumbers = 0;

System.out.println("\nNumbers having exactly " + x + " divisors are:");

for (int num = start; num <= end; num++) {
int divisors = countDivisors(num);

if (divisors == x) {
System.out.print(num + " ");
totalNumbers++;
}
}

System.out.println("\n\nTotal count = " + totalNumbers);

sc.close();
}
}

33 changes: 33 additions & 0 deletions Anisha_DaysInMonthGivenYear.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import java.util.Scanner;
public class Anisha_DaysInMonthGivenYear {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.print("Enter month (1-12): ");
int month = sc.nextInt();

System.out.print("Enter year: ");
int year = sc.nextInt();

if (month < 1 || month > 12) {
System.out.println("Invalid month! Enter between 1 to 12.");
}

else if ((month == 2) && ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0)))
System.out.println("Number of days is 29");

else if (month == 2)
System.out.println("Number of days is 28");

else if (month == 1 || month == 3 || month == 5 || month == 7 ||
month == 8 || month == 10 || month == 12)
System.out.println("Number of days is 31");

else
System.out.println("Number of days is 30");

sc.close();
}
}
20 changes: 20 additions & 0 deletions Anisha_DecimalToBinary.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import java.util.Scanner;
public class Anisha_DecimalToBinary {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a Decimal Number: ");
int num = sc.nextInt();
sc.close();
int[] binary = new int[32];
int index = 0;
while (num > 0) {
binary[index] = num % 2;
num = num / 2;
index++;
}
System.out.print("Binary value = ");
for (int i = index - 1; i >= 0; i--) {
System.out.print(binary[i]);
}
}
}
Loading