0% found this document useful (0 votes)
23 views

Assignment 4

The document contains 4 Java programs: 1) to calculate the sum of digits in a 3 digit number, 2) to reverse a 3 digit number, 3) to check if a 3 digit number is a palindrome, 4) to check if a number is a neon number.

Uploaded by

riddhimashetty28
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)
23 views

Assignment 4

The document contains 4 Java programs: 1) to calculate the sum of digits in a 3 digit number, 2) to reverse a 3 digit number, 3) to check if a 3 digit number is a palindrome, 4) to check if a number is a neon number.

Uploaded by

riddhimashetty28
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
You are on page 1/ 6

ASSIGNMENT-4

1) WAP to calculate sum of the digits


import java.util.Scanner;

class sum

public static void main(String args[])

Scanner sc=new Scanner(System.in);

int num,lno,sum=0;

System.out.println("Enter a three digit number");

num=sc.nextInt();

while(num>0)

lno=num%10;

sum=sum+lno;

num=num/10;

System.out.println("The sum of digits is:"+sum);

}
2) WAP to reverse number
import java.util.Scanner;

class reverse

public static void main(String args[])

Scanner sc = new Scanner(System.in);

int num,lno,rev=0;

System.out.print("Enter a three digit number");

num=sc.nextInt();

while(num>0)

lno=num%10;

rev=rev*10+lno;

num=num/10;

System.out.println("The reverse is:"+rev);

}
3) WAP to input any three digit number and check whether its palindrome number or
not
import java.util.Scanner;

class palindrome

public static void main(String[] args)

Scanner sc=new Scanner(System.in);

System.out.println("Enter a three digit num");

int num,temp,lno,sum=0;

num=sc.nextInt();

temp=num;

while(num>0)

lno=sum%10;

sum=sum*10+lno;

num=num/10;

if(temp==num)

System.out.println("The entered no is palindrome");

else
System.out.println("The entered no is not a palindrome");

4) WAP to check whether entered number is Neon Number or not.


import java.util.Scanner;

class neon

public static void main(String[] args)

Scanner sc=new Scanner(System.in);

System.out.println("Enter a num");

int num,temp,lno,sqrt,rev=0;

num=sc.nextInt();

temp=num;

sqrt=num*num;
while(sqrt>0)

lno=sqrt%10;

sqrt=sqrt*10+lno;

num=num/10;

if(sqrt==temp)

System.out.println("The entered no is neon");

else

System.out.println("The entered no is not a neon");

You might also like