0% found this document useful (0 votes)
12 views6 pages

Java Programs for Number Analysis and Patterns

The document contains multiple Java programs that perform various tasks, including checking if a number is friendly, identifying toll-free phone numbers, generating Fibonacci series, calculating factorials, and checking for prime numbers. It also includes programs for displaying patterns, calculating sums, and determining special number types like Neon, Xylem, and Phloem numbers. Each program prompts the user for input and provides output based on the specified functionality.
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)
12 views6 pages

Java Programs for Number Analysis and Patterns

The document contains multiple Java programs that perform various tasks, including checking if a number is friendly, identifying toll-free phone numbers, generating Fibonacci series, calculating factorials, and checking for prime numbers. It also includes programs for displaying patterns, calculating sums, and determining special number types like Neon, Xylem, and Phloem numbers. Each program prompts the user for input and provides output based on the specified functionality.
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

program 11

import [Link];
public class program11
{
public static void main()
{
Scanner sc = new Scanner([Link]);
[Link]("Input your 5 digit number");
int n = [Link]();
int l1,l2,l3,l4,l5 = 0;
if(n>9999 && n<=99999)
{
l1 = (n/10000);

l2 = (n/1000);

l3 = (n/100);

l4 = (n/10);
if(l1%1==0 && l2%2==0 && l3%3==0 && l4%4==0 && n%5 == 0)
[Link]("It is a friendly number");
else
[Link]("It is not a friendly number");
}
else
[Link]("The entered number is not a 5 digit number");

}
}
----------------------------------------------------------------------------
program 12
import [Link];
public class program12
{
public static void main()
{
Scanner sc = new Scanner([Link]);
[Link]("Input the phone number");
double n = [Link]();

if(n>=1000000000.0 && n<=(9*1111111111.0))


{
double num1 = n/10000000;
int num = (int)num1;
if(num == 800 || num == 888 || num == 877 || num == 866)
[Link]("It is a toll free number");
else
[Link]("Invalid Number(Not toll free)");

}
else
[Link]("Invalid Number(Not a 10 digit number)");
}
}
------------------------------------------------------------------------
program 13
import [Link];
public class program13
{
public static void main()
{
Scanner sc = new Scanner([Link]);
[Link]("Choose which program you want to execute \n A:
Fibonachi series \n B: The Factorial of a Number");
char choice = [Link]().charAt(0);
switch(choice)
{
case 'A':
[Link]("Input the number of digits in the series");
int n = [Link]();
int n1 = 0;
int n2 = 1;
int n3;
[Link]("Fibonachi series");
[Link](n1);
[Link](n2);
for(int x=1;x<=(n-2);x++)
{
n3 = n2 + n1;
[Link](n3);
n1=n2;
n2=n3;
}
[Link]();
break;

case 'B':
[Link]("The factorial of a numbers");
[Link]("Input your number");
int fn = [Link]();
int product = 1;
for(int y=1;y<=fn;y++)
{
product = product * y;
[Link](product);
}
[Link]("The factorial of "+fn+" is = "+product);
break;

default:
[Link]("Invalid Input");

}
}
}
--------------------------------------------------------------------------------
program 14
import [Link];
public class program14
{
public static void main()
{
Scanner sc = new Scanner([Link]);
[Link]("Choose what function you want to perform");
[Link]("A:Calculate the sum of all numbers below 100 divisibe
by 3 or 5 ");
[Link]("B:To input a number and check if it is a Neon number or
not");
char choice = [Link]().charAt(0);
int sum = 0;
switch(choice)
{
case 'A':
for(int x=0;x<100;x++)
{
if(x%3==0 || x%5==0)
{

sum = sum+x;
}
}
[Link]("he sum of all numbers below 100 that are divisible by 3
or 5 is =" +sum);
break;
case 'B':
[Link]("Input your number");
int n = [Link]();
int sum1 = 0;
int d;
int copy = n;
int n1 = n*n;
while(n1>0)
{
d = n1%10;
sum1 = sum1 + d;
n1 = n1/10;
}
if(sum1 == copy)
[Link]("The eneterd number is a neon number");
else
[Link]("The eneterd number is not a neon number");
break;
default:
[Link]("Invalid Input");
}

}
}
--------------------------------------------------------------
program 15
import [Link];
public class program15
{
public static void main()
{
Scanner sc = new Scanner([Link]);
[Link]("Input the 2 numbers that forms the start and end of the
range from which all the prime numbers in that range should be disaplyed");
int r1 = [Link]();
int r2 = [Link]();

for(int y=r1;y<=r2;y++)
{
int sum = 0;
for(int x=1;x<=y;x++)
{
if(y%x==0)
{
sum = sum + x;
}
}
if(sum==y+1)
{
[Link](y+",");
}
}

}
}
-----------------------------------------------------------------------------------
-----------
program 16
public class program16
{
public static void main()
{
int y = 1;
[Link]("Floyd's Triangle");
for(int r=1;r<=4;r++)
{
for(int c = 1;c<=r;c++)
{
[Link](y+"");
y++;
}
[Link]();
}
}
}
------------------------------------------------------------------------------
program 17
import [Link];
public class program17
{
public static void main()
{ Scanner sc = new Scanner([Link]);
[Link]("Choose which loop based pattern u want to be display 1
or 2");
[Link]("1st pattern");
[Link]("1 2 3 4 5 6 \n 1 2 3 4 5 \n 1 2 3 4 \n 1 2 3 \n 1 2 \n
1");
[Link]("2nd pattern");
[Link]("6 \n 5 6 \n 4 5 6 \n 3 4 5 6 \n 2 3 4 5 6 \n 1 2 3 4 5
6");
int choice = [Link]();
switch(choice)
{
case 1:

for(int b= 6;b>=1;b--)
{
for(int q=1;q<=b;q++)
[Link](q);
[Link]();
}
[Link]();
break;
case 2:
[Link]("2nd pattern");
[Link]();
for(int r=6;r>=1;r--)
{
for(int c=r;c<=6;c++)
[Link](c);
[Link]();

}
break;
default:
[Link]("Invalid Input");
break;

}
}
-------------------------------------------------------------------------
program 18
public class program18
{
public static void main()
{
for(char ch ='a';ch<='e';ch++)
{
for(char c='a';c<=ch;c++)
[Link](c);
for(char ch1=ch;ch1<'e';ch1++)
[Link]("*");
[Link]();
}
}
}
--------------------------------------------------------------
program 19
import [Link];
public class program19
{
public static void main()
{
Scanner sc = new Scanner([Link]);
[Link]("Inpt your number");
int n = [Link]();
int d1 = n%10;
n = n/10;
int copy = n;
int sum = 0;
int digit;
while(n>9)
{
digit = n%10;
sum = sum + digit;
n = n/10;
}

int extremesum = n + d1;

if(extremesum == sum)
[Link]("The entered number is a xylem number");
else
[Link]("The eneterd number is a phloem number");

}
}
------------------------------------------------------------------------
program 20
public class program20
{
public static void main()
{
for(int r=1;r<=5;r++)
{
for(int c = 1;c<=r;c++)
[Link](r*c);
[Link]();
}
}
}
-----------------------------------------------------------------------

Common questions

Powered by AI

The program uses a switch-case structure, where the user's choice (1 or 2) determines which pattern is printed. Each pattern has a nested loop structure; the first pattern decreases the row count by one each time, and the second pattern increases the numbers printed per row .

A neon number is verified by checking whether the sum of the digits of its square is equal to the number itself. The source squares the number, splits it into digits, sums those digits, and compares the sum to the original number for verification .

Floyd's Triangle is generated by printing numbers in a triangular format, with the first row having one number, the second row two numbers, and so on, until the fourth row. The numbers are printed in increasing order starting from 1, incrementing by 1 with each print .

The code checks if the input number is a valid 10-digit number by ensuring it is at least 1,000,000,000 and no more than 9,111,111,111. It then extracts the first three digits and checks if they match any toll-free prefixes (800, 888, 877, 866). If so, it is considered a toll-free number .

The nested loop structure generates a pattern where each row consists of numbers that are the product of row and column indices. With the outer loop iterating over rows and the inner loop over columns, it prints products of current row and column numbers .

A Xylem number is identified if the sum of its extreme digits equals the sum of its middle digits. The code computes the sums by isolating the first and last digits as extremes, and the rest as middle digits, comparing these two sums to classify the number as Xylem or Phloem .

The code iterates over each number in the specified range and calculates the sum of all divisors. If the sum of the divisors equals the number plus one, it indicates that the number is prime, as prime numbers have only two divisors: 1 and themselves .

The logic involves initializing the first two numbers of the Fibonacci series (0 and 1) and using a loop to calculate subsequent numbers. Each new number is the sum of the previous two numbers, and this process is repeated for 'n-2' iterations, where 'n' is the total number of Fibonacci numbers desired .

A friendly number in the source code is a five-digit number, where each digit has a specific property: the first digit is divisible by 1, the second by 2, the third by 3, the fourth by 4, and the entire number by 5 . If the number satisfies all these divisibility conditions, it is considered a friendly number.

The algorithm iterates through numbers from 0 to 99, adding each number to a sum if it is divisible by either 3 or 5. This is achieved by using a conditional within a loop that checks divisibility and accumulates the total if true .

You might also like