0% found this document useful (0 votes)
2K views

Sim Card Code Java

This Java program defines a SimCard class that takes a phone number as a parameter in its constructor. The checkNumber method separates the digits of the phone number into even and odd sums, compares the sums, and prints a statement about their relative values. The main method gets user input for a phone number, creates a SimCard object, and calls checkNumber to analyze and output the results.

Uploaded by

Amulya Rajesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views

Sim Card Code Java

This Java program defines a SimCard class that takes a phone number as a parameter in its constructor. The checkNumber method separates the digits of the phone number into even and odd sums, compares the sums, and prints a statement about their relative values. The main method gets user input for a phone number, creates a SimCard object, and calls checkNumber to analyze and output the results.

Uploaded by

Amulya Rajesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import java.util.

Scanner;

public class SimCard {


private long phoneNumber;

public SimCard(long phoneNumber) {


this.phoneNumber = phoneNumber;
}

public void checkNumber() {


long temp = phoneNumber;
int evenSum = 0;
int oddSum = 0;

while (temp > 0) {


int digit = (int) (temp % 10);
if (digit % 2 == 0) {
evenSum += digit;
} else {
oddSum += digit;
}
temp /= 10;
}

if (evenSum == oddSum) {
System.out.println("Sum of odd and even are equal");
} else if (evenSum > oddSum) {
System.out.println("Sum of even is greater than sum of odd");
} else {
System.out.println("Sum of odd is greater than sum of even");
}
}

public static void main(String[] args) {


Scanner scanner = new Scanner(System.in);
System.out.println("Enter the phone number:");
long phoneNumber = scanner.nextLong();
scanner.close();

SimCard simCard = new SimCard(phoneNumber);


simCard.checkNumber();
}
}

You might also like