0% found this document useful (0 votes)
2 views3 pages

Java Problems

The document contains three Java programs that perform different operations on digits. The first program calculates the sum of the digits of a number, the second reverses the digits, and the third checks if the number is a palindrome. Each program uses a while loop to process the input number and outputs the result accordingly.

Uploaded by

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

Java Problems

The document contains three Java programs that perform different operations on digits. The first program calculates the sum of the digits of a number, the second reverses the digits, and the third checks if the number is a palindrome. Each program uses a while loop to process the input number and outputs the result accordingly.

Uploaded by

nivashini1910
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

QUESTION 1: SUM OF DIGITS

import [Link].*;

class Sum {

public static void main(String args[]) {

Scanner sc = new Scanner([Link]);

int n, count=0,sum=0,r;

[Link]("Entr the digit: ");

n=[Link]();

while(n>0){

r=n%10;

sum=sum+r;

n=n/10;

count++;

[Link]("SUM:"+sum);

QUESTION 2: REVERSE THE DIGIT:

import [Link].*;

class Sum {

public static void main(String args[]) {

Scanner sc = new Scanner([Link]);

int n, count=0,sum=0,r,rev=0;

[Link]("Entr the digit: ");


n=[Link]();

while(n>0){

r=n%10;

rev=rev*10+r;

n=n/10;

count++;

[Link]("REV:"+rev);

QUESTION 3 : PALINDROME

import [Link].*;

class Sum {

public static void main(String args[]) {

Scanner sc = new Scanner([Link]);

int n, count=0,sum=0,r,rev=0,temp;

[Link]("Entr the digit: ");

n=[Link]();

temp=n;

while(n>0){

r=n%10;

rev=rev*10+r;

n=n/10;

count++;

if (temp==rev){

[Link]("Palindrome");
}

else{

[Link]("Not a Palindrome");

You might also like