SlideShare a Scribd company logo
1 of 6
Download to read offline
//Driver.java
import java.util.Scanner;
import java.text.DecimalFormat;
public class Driver
{
public static void printSequence (int num)
{
if(num > 0)
{
for (int i = 0; i <= num ;i++ )
{
System.out.print(i + " ");
}
System.out.println();
}
else if(num < 0)
{
for (int i = 0; i >= num ;i-- )
{
System.out.print(i + " ");
}
System.out.println();
}
}
public static int trianglarNum (int num)
{
int sum = 0;
if(num > 0)
{
for (int i = 1; i <= num ;i++ )
{
sum = sum + i;
}
return sum;
}
else
return -1;
}
public static void printArray(int list [])
{
for (int i = 0; i < list.length ;i++ )
{
System.out.print(list[i] + " ");
}
System.out.println();
}
public static int range(int list [])
{
int max,min;
max = list[0];
min = list[0];
for (int i = 1; i < list.length ;i++ )
{
if(list[i] > max)
max = list[i];
if(list[i] < min)
min = list[i];
}
System.out.println("difference between the maximum and minimum values in the array: "+
(max-min));
return (max-min);
}
public static void main(String[] args)
{
printSequence(10);
printSequence(-10);
System.out.println();
if(trianglarNum(10) > 0)
System.out.println("Sum: "+ trianglarNum(10));
else
System.out.println("Negative input ");
if(trianglarNum(-10) > 0)
System.out.println("Sum: "+ trianglarNum(-10));
else
System.out.println("Negative input  ");
int array[] = {1,2,4,5,-4,7,8,11,5,7};
printArray(array);
System.out.println();
System.out.println("difference between the maximum and minimum values in the array: "+
range(array));
}
}
/*
output:
0 1 2 3 4 5 6 7 8 9 10
0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10
Sum: 55
Negative input
1 2 4 5 -4 7 8 11 5 7
difference between the maximum and minimum values in the array: 15
difference between the maximum and minimum values in the array: 15
*/
Solution
//Driver.java
import java.util.Scanner;
import java.text.DecimalFormat;
public class Driver
{
public static void printSequence (int num)
{
if(num > 0)
{
for (int i = 0; i <= num ;i++ )
{
System.out.print(i + " ");
}
System.out.println();
}
else if(num < 0)
{
for (int i = 0; i >= num ;i-- )
{
System.out.print(i + " ");
}
System.out.println();
}
}
public static int trianglarNum (int num)
{
int sum = 0;
if(num > 0)
{
for (int i = 1; i <= num ;i++ )
{
sum = sum + i;
}
return sum;
}
else
return -1;
}
public static void printArray(int list [])
{
for (int i = 0; i < list.length ;i++ )
{
System.out.print(list[i] + " ");
}
System.out.println();
}
public static int range(int list [])
{
int max,min;
max = list[0];
min = list[0];
for (int i = 1; i < list.length ;i++ )
{
if(list[i] > max)
max = list[i];
if(list[i] < min)
min = list[i];
}
System.out.println("difference between the maximum and minimum values in the array: "+
(max-min));
return (max-min);
}
public static void main(String[] args)
{
printSequence(10);
printSequence(-10);
System.out.println();
if(trianglarNum(10) > 0)
System.out.println("Sum: "+ trianglarNum(10));
else
System.out.println("Negative input ");
if(trianglarNum(-10) > 0)
System.out.println("Sum: "+ trianglarNum(-10));
else
System.out.println("Negative input  ");
int array[] = {1,2,4,5,-4,7,8,11,5,7};
printArray(array);
System.out.println();
System.out.println("difference between the maximum and minimum values in the array: "+
range(array));
}
}
/*
output:
0 1 2 3 4 5 6 7 8 9 10
0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10
Sum: 55
Negative input
1 2 4 5 -4 7 8 11 5 7
difference between the maximum and minimum values in the array: 15
difference between the maximum and minimum values in the array: 15
*/

More Related Content

Similar to Java program to print sequences, calculate triangular numbers and find range of array

1. import java.util.Scanner; public class Alphabetical_Order {.pdf
1. import java.util.Scanner; public class Alphabetical_Order {.pdf1. import java.util.Scanner; public class Alphabetical_Order {.pdf
1. import java.util.Scanner; public class Alphabetical_Order {.pdfAnkitchhabra28
 
Sharable_Java_Python.pdf
Sharable_Java_Python.pdfSharable_Java_Python.pdf
Sharable_Java_Python.pdfICADCMLTPC
 
Hi, Please find my codeimport java.util.Random;public class Pro.pdf
Hi, Please find my codeimport java.util.Random;public class Pro.pdfHi, Please find my codeimport java.util.Random;public class Pro.pdf
Hi, Please find my codeimport java.util.Random;public class Pro.pdfanujsharmaanuj14
 
ArrayTest.java import java.util.Arrays; import java.util.Scann.pdf
ArrayTest.java import java.util.Arrays; import java.util.Scann.pdfArrayTest.java import java.util.Arrays; import java.util.Scann.pdf
ArrayTest.java import java.util.Arrays; import java.util.Scann.pdfdeepua8
 
import java.uti-WPS Office.docx
import java.uti-WPS Office.docximport java.uti-WPS Office.docx
import java.uti-WPS Office.docxKatecate1
 
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...Sunil Kumar Gunasekaran
 
Example of JAVA Program
Example of JAVA ProgramExample of JAVA Program
Example of JAVA ProgramTrenton Asbury
 
SumNumbers.java import java.util.Scanner;public class SumNumbe.pdf
SumNumbers.java import java.util.Scanner;public class SumNumbe.pdfSumNumbers.java import java.util.Scanner;public class SumNumbe.pdf
SumNumbers.java import java.util.Scanner;public class SumNumbe.pdfankkitextailes
 
Lab101.pptx
Lab101.pptxLab101.pptx
Lab101.pptxKimVeeL
 
import java.util.Scanner;public class Main {private static i.pdf
import java.util.Scanner;public class Main {private static i.pdfimport java.util.Scanner;public class Main {private static i.pdf
import java.util.Scanner;public class Main {private static i.pdfstopgolook
 
FileName EX06_1java Programmer import ja.pdf
FileName EX06_1java Programmer  import ja.pdfFileName EX06_1java Programmer  import ja.pdf
FileName EX06_1java Programmer import ja.pdfactocomputer
 
I need to create a data type that implement the following interface -.docx
I need to create a data type that implement the following interface -.docxI need to create a data type that implement the following interface -.docx
I need to create a data type that implement the following interface -.docxmckerliejonelle
 
Write the program in MIPS that declares an array of positive integer.pdf
Write the program in MIPS that declares an array of positive integer.pdfWrite the program in MIPS that declares an array of positive integer.pdf
Write the program in MIPS that declares an array of positive integer.pdfarihanthtoysandgifts
 

Similar to Java program to print sequences, calculate triangular numbers and find range of array (17)

1. import java.util.Scanner; public class Alphabetical_Order {.pdf
1. import java.util.Scanner; public class Alphabetical_Order {.pdf1. import java.util.Scanner; public class Alphabetical_Order {.pdf
1. import java.util.Scanner; public class Alphabetical_Order {.pdf
 
14 thread
14 thread14 thread
14 thread
 
Sharable_Java_Python.pdf
Sharable_Java_Python.pdfSharable_Java_Python.pdf
Sharable_Java_Python.pdf
 
Hi, Please find my codeimport java.util.Random;public class Pro.pdf
Hi, Please find my codeimport java.util.Random;public class Pro.pdfHi, Please find my codeimport java.util.Random;public class Pro.pdf
Hi, Please find my codeimport java.util.Random;public class Pro.pdf
 
ArrayTest.java import java.util.Arrays; import java.util.Scann.pdf
ArrayTest.java import java.util.Arrays; import java.util.Scann.pdfArrayTest.java import java.util.Arrays; import java.util.Scann.pdf
ArrayTest.java import java.util.Arrays; import java.util.Scann.pdf
 
import java.uti-WPS Office.docx
import java.uti-WPS Office.docximport java.uti-WPS Office.docx
import java.uti-WPS Office.docx
 
Huraira_waris_Assgnment_4.docx
Huraira_waris_Assgnment_4.docxHuraira_waris_Assgnment_4.docx
Huraira_waris_Assgnment_4.docx
 
Sam wd programs
Sam wd programsSam wd programs
Sam wd programs
 
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
 
Example of JAVA Program
Example of JAVA ProgramExample of JAVA Program
Example of JAVA Program
 
SumNumbers.java import java.util.Scanner;public class SumNumbe.pdf
SumNumbers.java import java.util.Scanner;public class SumNumbe.pdfSumNumbers.java import java.util.Scanner;public class SumNumbe.pdf
SumNumbers.java import java.util.Scanner;public class SumNumbe.pdf
 
Java programs
Java programsJava programs
Java programs
 
Lab101.pptx
Lab101.pptxLab101.pptx
Lab101.pptx
 
import java.util.Scanner;public class Main {private static i.pdf
import java.util.Scanner;public class Main {private static i.pdfimport java.util.Scanner;public class Main {private static i.pdf
import java.util.Scanner;public class Main {private static i.pdf
 
FileName EX06_1java Programmer import ja.pdf
FileName EX06_1java Programmer  import ja.pdfFileName EX06_1java Programmer  import ja.pdf
FileName EX06_1java Programmer import ja.pdf
 
I need to create a data type that implement the following interface -.docx
I need to create a data type that implement the following interface -.docxI need to create a data type that implement the following interface -.docx
I need to create a data type that implement the following interface -.docx
 
Write the program in MIPS that declares an array of positive integer.pdf
Write the program in MIPS that declares an array of positive integer.pdfWrite the program in MIPS that declares an array of positive integer.pdf
Write the program in MIPS that declares an array of positive integer.pdf
 

More from anandhomeneeds

Question 1,2,4 ------------------------------------Please check.pdf
Question 1,2,4 ------------------------------------Please check.pdfQuestion 1,2,4 ------------------------------------Please check.pdf
Question 1,2,4 ------------------------------------Please check.pdfanandhomeneeds
 
The answer is C. securin.APC degrade securin to release separase .pdf
The answer is C. securin.APC degrade securin to release separase .pdfThe answer is C. securin.APC degrade securin to release separase .pdf
The answer is C. securin.APC degrade securin to release separase .pdfanandhomeneeds
 
HiCan you please summarise the question. More information confuse .pdf
HiCan you please summarise the question. More information confuse .pdfHiCan you please summarise the question. More information confuse .pdf
HiCan you please summarise the question. More information confuse .pdfanandhomeneeds
 
What property of proteins us used to separate them in HICHydrophob.pdf
What property of proteins us used to separate them in HICHydrophob.pdfWhat property of proteins us used to separate them in HICHydrophob.pdf
What property of proteins us used to separate them in HICHydrophob.pdfanandhomeneeds
 
upload complete priblem somthing is missingSolutionupload comp.pdf
upload complete priblem somthing is missingSolutionupload comp.pdfupload complete priblem somthing is missingSolutionupload comp.pdf
upload complete priblem somthing is missingSolutionupload comp.pdfanandhomeneeds
 
the phenomena responsible for this type of inheritancce is Epistasis.pdf
the phenomena responsible for this type of inheritancce is Epistasis.pdfthe phenomena responsible for this type of inheritancce is Epistasis.pdf
the phenomena responsible for this type of inheritancce is Epistasis.pdfanandhomeneeds
 
The substrate in urease test is urea.The end products in urease te.pdf
The substrate in urease test is urea.The end products in urease te.pdfThe substrate in urease test is urea.The end products in urease te.pdf
The substrate in urease test is urea.The end products in urease te.pdfanandhomeneeds
 
later we create a specialstack class ,which inherits from stack cl.pdf
later we create a specialstack class ,which inherits from stack cl.pdflater we create a specialstack class ,which inherits from stack cl.pdf
later we create a specialstack class ,which inherits from stack cl.pdfanandhomeneeds
 
I think that 34SolutionI think that 34.pdf
I think that 34SolutionI think that 34.pdfI think that 34SolutionI think that 34.pdf
I think that 34SolutionI think that 34.pdfanandhomeneeds
 
D(ANSWER)Polycrystalline or multicrystalline materials, or polycry.pdf
D(ANSWER)Polycrystalline or multicrystalline materials, or polycry.pdfD(ANSWER)Polycrystalline or multicrystalline materials, or polycry.pdf
D(ANSWER)Polycrystalline or multicrystalline materials, or polycry.pdfanandhomeneeds
 
1.It is the process of directing the television assistances are tran.pdf
1.It is the process of directing the television assistances are tran.pdf1.It is the process of directing the television assistances are tran.pdf
1.It is the process of directing the television assistances are tran.pdfanandhomeneeds
 
Answer The major objective of implementing a health information man.pdf
Answer The major objective of implementing a health information man.pdfAnswer The major objective of implementing a health information man.pdf
Answer The major objective of implementing a health information man.pdfanandhomeneeds
 
The key assumptions made by the Hadoop Distributed File System(HDFS).pdf
The key assumptions made by the Hadoop Distributed File System(HDFS).pdfThe key assumptions made by the Hadoop Distributed File System(HDFS).pdf
The key assumptions made by the Hadoop Distributed File System(HDFS).pdfanandhomeneeds
 
Properties areMeanModeMedianQuartilesPercentilesRan.pdf
Properties areMeanModeMedianQuartilesPercentilesRan.pdfProperties areMeanModeMedianQuartilesPercentilesRan.pdf
Properties areMeanModeMedianQuartilesPercentilesRan.pdfanandhomeneeds
 
MgCO3 Increasing acidity will cause the following reaction Mg.pdf
 MgCO3 Increasing acidity will cause the following reaction Mg.pdf MgCO3 Increasing acidity will cause the following reaction Mg.pdf
MgCO3 Increasing acidity will cause the following reaction Mg.pdfanandhomeneeds
 
Environmental conditions play a key role in defining the function an.pdf
Environmental conditions play a key role in defining the function an.pdfEnvironmental conditions play a key role in defining the function an.pdf
Environmental conditions play a key role in defining the function an.pdfanandhomeneeds
 
1. Autralopith is a known genus of hominids which is extinct today..pdf
1. Autralopith is a known genus of hominids which is extinct today..pdf1. Autralopith is a known genus of hominids which is extinct today..pdf
1. Autralopith is a known genus of hominids which is extinct today..pdfanandhomeneeds
 
Mobile IP1) Mobile IP(MIP) is an Internet Engineering Task Force(.pdf
Mobile IP1) Mobile IP(MIP) is an Internet Engineering Task Force(.pdfMobile IP1) Mobile IP(MIP) is an Internet Engineering Task Force(.pdf
Mobile IP1) Mobile IP(MIP) is an Internet Engineering Task Force(.pdfanandhomeneeds
 
Answer1. Cells can generate many different tissue types endoderm,.pdf
Answer1. Cells can generate many different tissue types endoderm,.pdfAnswer1. Cells can generate many different tissue types endoderm,.pdf
Answer1. Cells can generate many different tissue types endoderm,.pdfanandhomeneeds
 
3 a) The trace of an nSolution3 a) The trace of an n.pdf
3 a) The trace of an nSolution3 a) The trace of an n.pdf3 a) The trace of an nSolution3 a) The trace of an n.pdf
3 a) The trace of an nSolution3 a) The trace of an n.pdfanandhomeneeds
 

More from anandhomeneeds (20)

Question 1,2,4 ------------------------------------Please check.pdf
Question 1,2,4 ------------------------------------Please check.pdfQuestion 1,2,4 ------------------------------------Please check.pdf
Question 1,2,4 ------------------------------------Please check.pdf
 
The answer is C. securin.APC degrade securin to release separase .pdf
The answer is C. securin.APC degrade securin to release separase .pdfThe answer is C. securin.APC degrade securin to release separase .pdf
The answer is C. securin.APC degrade securin to release separase .pdf
 
HiCan you please summarise the question. More information confuse .pdf
HiCan you please summarise the question. More information confuse .pdfHiCan you please summarise the question. More information confuse .pdf
HiCan you please summarise the question. More information confuse .pdf
 
What property of proteins us used to separate them in HICHydrophob.pdf
What property of proteins us used to separate them in HICHydrophob.pdfWhat property of proteins us used to separate them in HICHydrophob.pdf
What property of proteins us used to separate them in HICHydrophob.pdf
 
upload complete priblem somthing is missingSolutionupload comp.pdf
upload complete priblem somthing is missingSolutionupload comp.pdfupload complete priblem somthing is missingSolutionupload comp.pdf
upload complete priblem somthing is missingSolutionupload comp.pdf
 
the phenomena responsible for this type of inheritancce is Epistasis.pdf
the phenomena responsible for this type of inheritancce is Epistasis.pdfthe phenomena responsible for this type of inheritancce is Epistasis.pdf
the phenomena responsible for this type of inheritancce is Epistasis.pdf
 
The substrate in urease test is urea.The end products in urease te.pdf
The substrate in urease test is urea.The end products in urease te.pdfThe substrate in urease test is urea.The end products in urease te.pdf
The substrate in urease test is urea.The end products in urease te.pdf
 
later we create a specialstack class ,which inherits from stack cl.pdf
later we create a specialstack class ,which inherits from stack cl.pdflater we create a specialstack class ,which inherits from stack cl.pdf
later we create a specialstack class ,which inherits from stack cl.pdf
 
I think that 34SolutionI think that 34.pdf
I think that 34SolutionI think that 34.pdfI think that 34SolutionI think that 34.pdf
I think that 34SolutionI think that 34.pdf
 
D(ANSWER)Polycrystalline or multicrystalline materials, or polycry.pdf
D(ANSWER)Polycrystalline or multicrystalline materials, or polycry.pdfD(ANSWER)Polycrystalline or multicrystalline materials, or polycry.pdf
D(ANSWER)Polycrystalline or multicrystalline materials, or polycry.pdf
 
1.It is the process of directing the television assistances are tran.pdf
1.It is the process of directing the television assistances are tran.pdf1.It is the process of directing the television assistances are tran.pdf
1.It is the process of directing the television assistances are tran.pdf
 
Answer The major objective of implementing a health information man.pdf
Answer The major objective of implementing a health information man.pdfAnswer The major objective of implementing a health information man.pdf
Answer The major objective of implementing a health information man.pdf
 
The key assumptions made by the Hadoop Distributed File System(HDFS).pdf
The key assumptions made by the Hadoop Distributed File System(HDFS).pdfThe key assumptions made by the Hadoop Distributed File System(HDFS).pdf
The key assumptions made by the Hadoop Distributed File System(HDFS).pdf
 
Properties areMeanModeMedianQuartilesPercentilesRan.pdf
Properties areMeanModeMedianQuartilesPercentilesRan.pdfProperties areMeanModeMedianQuartilesPercentilesRan.pdf
Properties areMeanModeMedianQuartilesPercentilesRan.pdf
 
MgCO3 Increasing acidity will cause the following reaction Mg.pdf
 MgCO3 Increasing acidity will cause the following reaction Mg.pdf MgCO3 Increasing acidity will cause the following reaction Mg.pdf
MgCO3 Increasing acidity will cause the following reaction Mg.pdf
 
Environmental conditions play a key role in defining the function an.pdf
Environmental conditions play a key role in defining the function an.pdfEnvironmental conditions play a key role in defining the function an.pdf
Environmental conditions play a key role in defining the function an.pdf
 
1. Autralopith is a known genus of hominids which is extinct today..pdf
1. Autralopith is a known genus of hominids which is extinct today..pdf1. Autralopith is a known genus of hominids which is extinct today..pdf
1. Autralopith is a known genus of hominids which is extinct today..pdf
 
Mobile IP1) Mobile IP(MIP) is an Internet Engineering Task Force(.pdf
Mobile IP1) Mobile IP(MIP) is an Internet Engineering Task Force(.pdfMobile IP1) Mobile IP(MIP) is an Internet Engineering Task Force(.pdf
Mobile IP1) Mobile IP(MIP) is an Internet Engineering Task Force(.pdf
 
Answer1. Cells can generate many different tissue types endoderm,.pdf
Answer1. Cells can generate many different tissue types endoderm,.pdfAnswer1. Cells can generate many different tissue types endoderm,.pdf
Answer1. Cells can generate many different tissue types endoderm,.pdf
 
3 a) The trace of an nSolution3 a) The trace of an n.pdf
3 a) The trace of an nSolution3 a) The trace of an n.pdf3 a) The trace of an nSolution3 a) The trace of an n.pdf
3 a) The trace of an nSolution3 a) The trace of an n.pdf
 

Recently uploaded

MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 

Java program to print sequences, calculate triangular numbers and find range of array

  • 1. //Driver.java import java.util.Scanner; import java.text.DecimalFormat; public class Driver { public static void printSequence (int num) { if(num > 0) { for (int i = 0; i <= num ;i++ ) { System.out.print(i + " "); } System.out.println(); } else if(num < 0) { for (int i = 0; i >= num ;i-- ) { System.out.print(i + " "); } System.out.println(); } } public static int trianglarNum (int num) { int sum = 0; if(num > 0) { for (int i = 1; i <= num ;i++ ) { sum = sum + i; } return sum;
  • 2. } else return -1; } public static void printArray(int list []) { for (int i = 0; i < list.length ;i++ ) { System.out.print(list[i] + " "); } System.out.println(); } public static int range(int list []) { int max,min; max = list[0]; min = list[0]; for (int i = 1; i < list.length ;i++ ) { if(list[i] > max) max = list[i]; if(list[i] < min) min = list[i]; } System.out.println("difference between the maximum and minimum values in the array: "+ (max-min)); return (max-min); } public static void main(String[] args) { printSequence(10); printSequence(-10); System.out.println(); if(trianglarNum(10) > 0) System.out.println("Sum: "+ trianglarNum(10)); else
  • 3. System.out.println("Negative input "); if(trianglarNum(-10) > 0) System.out.println("Sum: "+ trianglarNum(-10)); else System.out.println("Negative input "); int array[] = {1,2,4,5,-4,7,8,11,5,7}; printArray(array); System.out.println(); System.out.println("difference between the maximum and minimum values in the array: "+ range(array)); } } /* output: 0 1 2 3 4 5 6 7 8 9 10 0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 Sum: 55 Negative input 1 2 4 5 -4 7 8 11 5 7 difference between the maximum and minimum values in the array: 15 difference between the maximum and minimum values in the array: 15 */ Solution //Driver.java import java.util.Scanner; import java.text.DecimalFormat; public class Driver { public static void printSequence (int num) { if(num > 0) {
  • 4. for (int i = 0; i <= num ;i++ ) { System.out.print(i + " "); } System.out.println(); } else if(num < 0) { for (int i = 0; i >= num ;i-- ) { System.out.print(i + " "); } System.out.println(); } } public static int trianglarNum (int num) { int sum = 0; if(num > 0) { for (int i = 1; i <= num ;i++ ) { sum = sum + i; } return sum; } else return -1; } public static void printArray(int list []) { for (int i = 0; i < list.length ;i++ ) { System.out.print(list[i] + " "); } System.out.println();
  • 5. } public static int range(int list []) { int max,min; max = list[0]; min = list[0]; for (int i = 1; i < list.length ;i++ ) { if(list[i] > max) max = list[i]; if(list[i] < min) min = list[i]; } System.out.println("difference between the maximum and minimum values in the array: "+ (max-min)); return (max-min); } public static void main(String[] args) { printSequence(10); printSequence(-10); System.out.println(); if(trianglarNum(10) > 0) System.out.println("Sum: "+ trianglarNum(10)); else System.out.println("Negative input "); if(trianglarNum(-10) > 0) System.out.println("Sum: "+ trianglarNum(-10)); else System.out.println("Negative input "); int array[] = {1,2,4,5,-4,7,8,11,5,7}; printArray(array); System.out.println(); System.out.println("difference between the maximum and minimum values in the array: "+ range(array)); }
  • 6. } /* output: 0 1 2 3 4 5 6 7 8 9 10 0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 Sum: 55 Negative input 1 2 4 5 -4 7 8 11 5 7 difference between the maximum and minimum values in the array: 15 difference between the maximum and minimum values in the array: 15 */