SlideShare a Scribd company logo

Using JAVA There is very deep and strong river and the only way one pe.docx

S
slyndon

Using JAVA There is very deep and strong river and the only way one person can cross the river is to jump on the stones. There are N-1 stones on river from one side to another, placed in equal distances. If we give numbers to stones, we have 1, 2, 3,...,N-1 and the other side of the river can be numbered as N. A person can only jump to stone infront of him, or to the next one or to the next next one, but not longer. In other words, one possibility to cross the river is: {1, 2, 3,..., N}, another possibility is: { 3, 4,..., N} and another one is {3,6,9,.., N}, and so on. Design and implement an algorihtm to print number of possibilities and all possible paths to cross the river, when n is given. For example; when n=4 is given, it should print these lines to the screen: Pseudocode for your algorithm. Your Java file that implements the algorithm. Output files of your running program for three different n values: n=6, n=7, and n=8. Solution java code public class RiverCrossing { private int noOfways; public void noOfWaysToCross(int n){ int f1=1,f2=2,f3=0; noOfways=0; while(f3<=n){ f3=f1+f2; noOfways+=f3; f1=f2; f2=f3; } System.out.println(\"No. of ways to cross the river: \"+noOfways); } public static void main(String[] args) { RiverCrossing r=new RiverCrossing(); r.noOfWaysToCross(6); r.noOfWaysToCross(7); r.noOfWaysToCross(8); } } .

1 of 1
Download to read offline
Using JAVA
There is very deep and strong river and the only way one person can cross the river is to jump on
the stones. There are N-1 stones on river from one side to another, placed in equal distances. If
we give numbers to stones, we have 1, 2, 3,...,N-1 and the other side of the river can be
numbered as N. A person can only jump to stone infront of him, or to the next one or to the next
next one, but not longer. In other words, one possibility to cross the river is: {1, 2, 3,..., N},
another possibility is: { 3, 4,..., N} and another one is {3,6,9,.., N}, and so on. Design and
implement an algorihtm to print number of possibilities and all possible paths to cross the river,
when n is given. For example; when n=4 is given, it should print these lines to the screen:
Pseudocode for your algorithm. Your Java file that implements the algorithm. Output files of
your running program for three different n values: n=6, n=7, and n=8.
Solution
java code public class RiverCrossing { private int noOfways; public void noOfWaysToCross(int
n){ int f1=1,f2=2,f3=0; noOfways=0; while(f3<=n){ f3=f1+f2; noOfways+=f3; f1=f2; f2=f3; }
System.out.println("No. of ways to cross the river: "+noOfways); } public static void
main(String[] args) { RiverCrossing r=new RiverCrossing(); r.noOfWaysToCross(6);
r.noOfWaysToCross(7); r.noOfWaysToCross(8); } }

Recommended

Use the table below to answer the following questions- A(4) ---------.docx
Use the table below to answer the following questions- A(4) ---------.docxUse the table below to answer the following questions- A(4) ---------.docx
Use the table below to answer the following questions- A(4) ---------.docxslyndon
 
Use the Table x y 1 1 2 1+2 3 1+2+4 4 1+2+4+8 a-Extend the t.docx
Use the Table  x y  1 1  2 1+2  3 1+2+4  4 1+2+4+8      a-Extend the t.docxUse the Table  x y  1 1  2 1+2  3 1+2+4  4 1+2+4+8      a-Extend the t.docx
Use the Table x y 1 1 2 1+2 3 1+2+4 4 1+2+4+8 a-Extend the t.docxslyndon
 
Use the redox table below to answer the following questions- a) Would.docx
Use the redox table below to answer the following questions- a) Would.docxUse the redox table below to answer the following questions- a) Would.docx
Use the redox table below to answer the following questions- a) Would.docxslyndon
 
Use the References to access important values if needed for this quest (4).docx
Use the References to access important values if needed for this quest (4).docxUse the References to access important values if needed for this quest (4).docx
Use the References to access important values if needed for this quest (4).docxslyndon
 
Use the References to access important values if needed for this quest.docx
Use the References to access important values if needed for this quest.docxUse the References to access important values if needed for this quest.docx
Use the References to access important values if needed for this quest.docxslyndon
 
Use the power method- in Matlab to determine the highest eigenvalue an.docx
Use the power method- in Matlab to determine the highest eigenvalue an.docxUse the power method- in Matlab to determine the highest eigenvalue an.docx
Use the power method- in Matlab to determine the highest eigenvalue an.docxslyndon
 
Use the MBR (nearest neighbor) technique to classify this wine- (use t.docx
Use the MBR (nearest neighbor) technique to classify this wine- (use t.docxUse the MBR (nearest neighbor) technique to classify this wine- (use t.docx
Use the MBR (nearest neighbor) technique to classify this wine- (use t.docxslyndon
 
Use the Hazen-Williams equation to compute friction loss with C-120- A.docx
Use the Hazen-Williams equation to compute friction loss with C-120- A.docxUse the Hazen-Williams equation to compute friction loss with C-120- A.docx
Use the Hazen-Williams equation to compute friction loss with C-120- A.docxslyndon
 

More Related Content

More from slyndon

Use the four compounds below to answer the questions-Of the four chemi.docx
Use the four compounds below to answer the questions-Of the four chemi.docxUse the four compounds below to answer the questions-Of the four chemi.docx
Use the four compounds below to answer the questions-Of the four chemi.docxslyndon
 
Use the following information- a- Beginning cash balance on March 1- $.docx
Use the following information- a- Beginning cash balance on March 1- $.docxUse the following information- a- Beginning cash balance on March 1- $.docx
Use the following information- a- Beginning cash balance on March 1- $.docxslyndon
 
Use the following information to answer the next question- The followi.docx
Use the following information to answer the next question- The followi.docxUse the following information to answer the next question- The followi.docx
Use the following information to answer the next question- The followi.docxslyndon
 
Use the following information Prepare a cash budget for the month end.docx
Use the following information  Prepare a cash budget for the month end.docxUse the following information  Prepare a cash budget for the month end.docx
Use the following information Prepare a cash budget for the month end.docxslyndon
 
Use the following ERD for questions a- and b (a) when we create the p.docx
Use the following ERD for questions a- and b  (a) when we create the p.docxUse the following ERD for questions a- and b  (a) when we create the p.docx
Use the following ERD for questions a- and b (a) when we create the p.docxslyndon
 
Use the Factor Theorem to determine whether x - c is a factor of f- I.docx
Use the Factor Theorem  to determine whether x - c is a factor of f- I.docxUse the Factor Theorem  to determine whether x - c is a factor of f- I.docx
Use the Factor Theorem to determine whether x - c is a factor of f- I.docxslyndon
 
Use the below table to answer the following questions-Selling price -.docx
Use the below table to answer the following questions-Selling price -.docxUse the below table to answer the following questions-Selling price -.docx
Use the below table to answer the following questions-Selling price -.docxslyndon
 
Use strong induction to prove that T(n) O(log n) where T(1) - 10 and.docx
Use strong induction to prove that T(n)  O(log n) where T(1) - 10 and.docxUse strong induction to prove that T(n)  O(log n) where T(1) - 10 and.docx
Use strong induction to prove that T(n) O(log n) where T(1) - 10 and.docxslyndon
 
Use STROBE to analyze Annas written observations about Hy Perteks- Now.docx
Use STROBE to analyze Annas written observations about Hy Perteks- Now.docxUse STROBE to analyze Annas written observations about Hy Perteks- Now.docx
Use STROBE to analyze Annas written observations about Hy Perteks- Now.docxslyndon
 
Use SQL to Create a table with at least 4 attributes one of which is t.docx
Use SQL to Create a table with at least 4 attributes one of which is t.docxUse SQL to Create a table with at least 4 attributes one of which is t.docx
Use SQL to Create a table with at least 4 attributes one of which is t.docxslyndon
 
Use row reduction to determine all values of and for which the syste.docx
Use row reduction to determine all values of  and  for which the syste.docxUse row reduction to determine all values of  and  for which the syste.docx
Use row reduction to determine all values of and for which the syste.docxslyndon
 
Use RIMS to create and run a program as a solution to each of the two.docx
Use RIMS to create and run a program as a solution to each of the two.docxUse RIMS to create and run a program as a solution to each of the two.docx
Use RIMS to create and run a program as a solution to each of the two.docxslyndon
 
Use pseudocode to write a recursive algorithm to search an unordered b.docx
Use pseudocode to write a recursive algorithm to search an unordered b.docxUse pseudocode to write a recursive algorithm to search an unordered b.docx
Use pseudocode to write a recursive algorithm to search an unordered b.docxslyndon
 
Use Nodal only- Write the 2 equations and solve them for y- Vi and V2-.docx
Use Nodal only- Write the 2 equations and solve them for y- Vi and V2-.docxUse Nodal only- Write the 2 equations and solve them for y- Vi and V2-.docx
Use Nodal only- Write the 2 equations and solve them for y- Vi and V2-.docxslyndon
 
Using your own words and one complete sentence per term- define the fo.docx
Using your own words and one complete sentence per term- define the fo.docxUsing your own words and one complete sentence per term- define the fo.docx
Using your own words and one complete sentence per term- define the fo.docxslyndon
 
Using java Given an aeroplane-'s acceleration and take-off speed- the.docx
Using java Given an aeroplane-'s acceleration and take-off speed- the.docxUsing java Given an aeroplane-'s acceleration and take-off speed- the.docx
Using java Given an aeroplane-'s acceleration and take-off speed- the.docxslyndon
 
Using the tables above- what would be the present value of $8-000 (rou.docx
Using the tables above- what would be the present value of $8-000 (rou.docxUsing the tables above- what would be the present value of $8-000 (rou.docx
Using the tables above- what would be the present value of $8-000 (rou.docxslyndon
 
using the same data assume that shoreline prorates Overapplied or unde.docx
using the same data assume that shoreline prorates Overapplied or unde.docxusing the same data assume that shoreline prorates Overapplied or unde.docx
using the same data assume that shoreline prorates Overapplied or unde.docxslyndon
 
Using this competing values model- what type of cultural profile would (1).docx
Using this competing values model- what type of cultural profile would (1).docxUsing this competing values model- what type of cultural profile would (1).docx
Using this competing values model- what type of cultural profile would (1).docxslyndon
 
Using this competing values model- what type of cultural profile would.docx
Using this competing values model- what type of cultural profile would.docxUsing this competing values model- what type of cultural profile would.docx
Using this competing values model- what type of cultural profile would.docxslyndon
 

More from slyndon (20)

Use the four compounds below to answer the questions-Of the four chemi.docx
Use the four compounds below to answer the questions-Of the four chemi.docxUse the four compounds below to answer the questions-Of the four chemi.docx
Use the four compounds below to answer the questions-Of the four chemi.docx
 
Use the following information- a- Beginning cash balance on March 1- $.docx
Use the following information- a- Beginning cash balance on March 1- $.docxUse the following information- a- Beginning cash balance on March 1- $.docx
Use the following information- a- Beginning cash balance on March 1- $.docx
 
Use the following information to answer the next question- The followi.docx
Use the following information to answer the next question- The followi.docxUse the following information to answer the next question- The followi.docx
Use the following information to answer the next question- The followi.docx
 
Use the following information Prepare a cash budget for the month end.docx
Use the following information  Prepare a cash budget for the month end.docxUse the following information  Prepare a cash budget for the month end.docx
Use the following information Prepare a cash budget for the month end.docx
 
Use the following ERD for questions a- and b (a) when we create the p.docx
Use the following ERD for questions a- and b  (a) when we create the p.docxUse the following ERD for questions a- and b  (a) when we create the p.docx
Use the following ERD for questions a- and b (a) when we create the p.docx
 
Use the Factor Theorem to determine whether x - c is a factor of f- I.docx
Use the Factor Theorem  to determine whether x - c is a factor of f- I.docxUse the Factor Theorem  to determine whether x - c is a factor of f- I.docx
Use the Factor Theorem to determine whether x - c is a factor of f- I.docx
 
Use the below table to answer the following questions-Selling price -.docx
Use the below table to answer the following questions-Selling price -.docxUse the below table to answer the following questions-Selling price -.docx
Use the below table to answer the following questions-Selling price -.docx
 
Use strong induction to prove that T(n) O(log n) where T(1) - 10 and.docx
Use strong induction to prove that T(n)  O(log n) where T(1) - 10 and.docxUse strong induction to prove that T(n)  O(log n) where T(1) - 10 and.docx
Use strong induction to prove that T(n) O(log n) where T(1) - 10 and.docx
 
Use STROBE to analyze Annas written observations about Hy Perteks- Now.docx
Use STROBE to analyze Annas written observations about Hy Perteks- Now.docxUse STROBE to analyze Annas written observations about Hy Perteks- Now.docx
Use STROBE to analyze Annas written observations about Hy Perteks- Now.docx
 
Use SQL to Create a table with at least 4 attributes one of which is t.docx
Use SQL to Create a table with at least 4 attributes one of which is t.docxUse SQL to Create a table with at least 4 attributes one of which is t.docx
Use SQL to Create a table with at least 4 attributes one of which is t.docx
 
Use row reduction to determine all values of and for which the syste.docx
Use row reduction to determine all values of  and  for which the syste.docxUse row reduction to determine all values of  and  for which the syste.docx
Use row reduction to determine all values of and for which the syste.docx
 
Use RIMS to create and run a program as a solution to each of the two.docx
Use RIMS to create and run a program as a solution to each of the two.docxUse RIMS to create and run a program as a solution to each of the two.docx
Use RIMS to create and run a program as a solution to each of the two.docx
 
Use pseudocode to write a recursive algorithm to search an unordered b.docx
Use pseudocode to write a recursive algorithm to search an unordered b.docxUse pseudocode to write a recursive algorithm to search an unordered b.docx
Use pseudocode to write a recursive algorithm to search an unordered b.docx
 
Use Nodal only- Write the 2 equations and solve them for y- Vi and V2-.docx
Use Nodal only- Write the 2 equations and solve them for y- Vi and V2-.docxUse Nodal only- Write the 2 equations and solve them for y- Vi and V2-.docx
Use Nodal only- Write the 2 equations and solve them for y- Vi and V2-.docx
 
Using your own words and one complete sentence per term- define the fo.docx
Using your own words and one complete sentence per term- define the fo.docxUsing your own words and one complete sentence per term- define the fo.docx
Using your own words and one complete sentence per term- define the fo.docx
 
Using java Given an aeroplane-'s acceleration and take-off speed- the.docx
Using java Given an aeroplane-'s acceleration and take-off speed- the.docxUsing java Given an aeroplane-'s acceleration and take-off speed- the.docx
Using java Given an aeroplane-'s acceleration and take-off speed- the.docx
 
Using the tables above- what would be the present value of $8-000 (rou.docx
Using the tables above- what would be the present value of $8-000 (rou.docxUsing the tables above- what would be the present value of $8-000 (rou.docx
Using the tables above- what would be the present value of $8-000 (rou.docx
 
using the same data assume that shoreline prorates Overapplied or unde.docx
using the same data assume that shoreline prorates Overapplied or unde.docxusing the same data assume that shoreline prorates Overapplied or unde.docx
using the same data assume that shoreline prorates Overapplied or unde.docx
 
Using this competing values model- what type of cultural profile would (1).docx
Using this competing values model- what type of cultural profile would (1).docxUsing this competing values model- what type of cultural profile would (1).docx
Using this competing values model- what type of cultural profile would (1).docx
 
Using this competing values model- what type of cultural profile would.docx
Using this competing values model- what type of cultural profile would.docxUsing this competing values model- what type of cultural profile would.docx
Using this competing values model- what type of cultural profile would.docx
 

Recently uploaded

Decision on Curriculum Change Path: Towards Standards-Based Curriculum in Ghana
Decision on Curriculum Change Path: Towards Standards-Based Curriculum in GhanaDecision on Curriculum Change Path: Towards Standards-Based Curriculum in Ghana
Decision on Curriculum Change Path: Towards Standards-Based Curriculum in GhanaPrince Armah, PhD
 
Unit 5th topic Drugs used in congestive Heart failure and shock.pdf
Unit 5th topic Drugs used in congestive Heart failure and shock.pdfUnit 5th topic Drugs used in congestive Heart failure and shock.pdf
Unit 5th topic Drugs used in congestive Heart failure and shock.pdfSUMIT TIWARI
 
MEC MAJUBA SADDENED BY THE PASSING AWAY OF THREE TEACHERS FOLLOWING A CAR ACC...
MEC MAJUBA SADDENED BY THE PASSING AWAY OF THREE TEACHERS FOLLOWING A CAR ACC...MEC MAJUBA SADDENED BY THE PASSING AWAY OF THREE TEACHERS FOLLOWING A CAR ACC...
MEC MAJUBA SADDENED BY THE PASSING AWAY OF THREE TEACHERS FOLLOWING A CAR ACC...SABC News
 
Permeation enhancer of Transdermal drug delivery system
Permeation enhancer of Transdermal drug delivery systemPermeation enhancer of Transdermal drug delivery system
Permeation enhancer of Transdermal drug delivery systemchetanpatil2572000
 
Database Security Methods, DAC, MAC,View
Database Security Methods, DAC, MAC,ViewDatabase Security Methods, DAC, MAC,View
Database Security Methods, DAC, MAC,ViewDr-Dipali Meher
 
How To Create Record Rules in the Odoo 17
How To Create Record Rules in the Odoo 17How To Create Record Rules in the Odoo 17
How To Create Record Rules in the Odoo 17Celine George
 
ICS2208 Lecture 2 Slides Interfaces_.pdf
ICS2208 Lecture 2 Slides Interfaces_.pdfICS2208 Lecture 2 Slides Interfaces_.pdf
ICS2208 Lecture 2 Slides Interfaces_.pdfVanessa Camilleri
 
PMI TAMIZHAGAM - A PMI CHENNAI CHAPTER'S NEWSLETTER - Q1FY24.pdf
PMI TAMIZHAGAM - A PMI CHENNAI CHAPTER'S NEWSLETTER - Q1FY24.pdfPMI TAMIZHAGAM - A PMI CHENNAI CHAPTER'S NEWSLETTER - Q1FY24.pdf
PMI TAMIZHAGAM - A PMI CHENNAI CHAPTER'S NEWSLETTER - Q1FY24.pdfvptechnology2
 
Genetics, Heredity, Variation, history, its roles, Scope, Importance, and Bra...
Genetics, Heredity, Variation, history, its roles, Scope, Importance, and Bra...Genetics, Heredity, Variation, history, its roles, Scope, Importance, and Bra...
Genetics, Heredity, Variation, history, its roles, Scope, Importance, and Bra...AKSHAYMAGAR17
 
2024-02-24_Session 1 - PMLE_UPDATED.pptx
2024-02-24_Session 1 - PMLE_UPDATED.pptx2024-02-24_Session 1 - PMLE_UPDATED.pptx
2024-02-24_Session 1 - PMLE_UPDATED.pptxgdgsurrey
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxdeputymitchell2
 
A Free eBook ~ Mental Exercise ...Puzzles to Analyze.pdf
A Free eBook ~ Mental Exercise ...Puzzles to Analyze.pdfA Free eBook ~ Mental Exercise ...Puzzles to Analyze.pdf
A Free eBook ~ Mental Exercise ...Puzzles to Analyze.pdfOH TEIK BIN
 
Relational_Algebra_Calculus Operations.pdf
Relational_Algebra_Calculus Operations.pdfRelational_Algebra_Calculus Operations.pdf
Relational_Algebra_Calculus Operations.pdfChristalin Nelson
 
天橋立 観光メモ 2024-30-302-2-Amanohashidate Sightseeing Memo.pptx
天橋立 観光メモ 2024-30-302-2-Amanohashidate Sightseeing Memo.pptx天橋立 観光メモ 2024-30-302-2-Amanohashidate Sightseeing Memo.pptx
天橋立 観光メモ 2024-30-302-2-Amanohashidate Sightseeing Memo.pptxMasami YASUDA
 
Organic Synthesis and Estimation of Functional Groups
Organic Synthesis and Estimation of Functional GroupsOrganic Synthesis and Estimation of Functional Groups
Organic Synthesis and Estimation of Functional GroupsDr.M.Geethavani
 
Capitol Doctoral Presentation -Feb 2024.pptx
Capitol Doctoral Presentation -Feb 2024.pptxCapitol Doctoral Presentation -Feb 2024.pptx
Capitol Doctoral Presentation -Feb 2024.pptxCapitolTechU
 
Discussing the new Competence Framework for project managers in the built env...
Discussing the new Competence Framework for project managers in the built env...Discussing the new Competence Framework for project managers in the built env...
Discussing the new Competence Framework for project managers in the built env...Association for Project Management
 
Practical Research 1, Lesson 5: DESIGNING A RESEARCH PROJECT RELATED TO DAILY...
Practical Research 1, Lesson 5: DESIGNING A RESEARCH PROJECT RELATED TO DAILY...Practical Research 1, Lesson 5: DESIGNING A RESEARCH PROJECT RELATED TO DAILY...
Practical Research 1, Lesson 5: DESIGNING A RESEARCH PROJECT RELATED TO DAILY...Katherine Villaluna
 
Mycology Update February 2024 Microbes with Morgan
Mycology Update February 2024 Microbes with MorganMycology Update February 2024 Microbes with Morgan
Mycology Update February 2024 Microbes with MorganMargie Morgan
 
Kartik Nair In Media Res Media Component
Kartik Nair In Media Res Media ComponentKartik Nair In Media Res Media Component
Kartik Nair In Media Res Media ComponentInMediaRes1
 

Recently uploaded (20)

Decision on Curriculum Change Path: Towards Standards-Based Curriculum in Ghana
Decision on Curriculum Change Path: Towards Standards-Based Curriculum in GhanaDecision on Curriculum Change Path: Towards Standards-Based Curriculum in Ghana
Decision on Curriculum Change Path: Towards Standards-Based Curriculum in Ghana
 
Unit 5th topic Drugs used in congestive Heart failure and shock.pdf
Unit 5th topic Drugs used in congestive Heart failure and shock.pdfUnit 5th topic Drugs used in congestive Heart failure and shock.pdf
Unit 5th topic Drugs used in congestive Heart failure and shock.pdf
 
MEC MAJUBA SADDENED BY THE PASSING AWAY OF THREE TEACHERS FOLLOWING A CAR ACC...
MEC MAJUBA SADDENED BY THE PASSING AWAY OF THREE TEACHERS FOLLOWING A CAR ACC...MEC MAJUBA SADDENED BY THE PASSING AWAY OF THREE TEACHERS FOLLOWING A CAR ACC...
MEC MAJUBA SADDENED BY THE PASSING AWAY OF THREE TEACHERS FOLLOWING A CAR ACC...
 
Permeation enhancer of Transdermal drug delivery system
Permeation enhancer of Transdermal drug delivery systemPermeation enhancer of Transdermal drug delivery system
Permeation enhancer of Transdermal drug delivery system
 
Database Security Methods, DAC, MAC,View
Database Security Methods, DAC, MAC,ViewDatabase Security Methods, DAC, MAC,View
Database Security Methods, DAC, MAC,View
 
How To Create Record Rules in the Odoo 17
How To Create Record Rules in the Odoo 17How To Create Record Rules in the Odoo 17
How To Create Record Rules in the Odoo 17
 
ICS2208 Lecture 2 Slides Interfaces_.pdf
ICS2208 Lecture 2 Slides Interfaces_.pdfICS2208 Lecture 2 Slides Interfaces_.pdf
ICS2208 Lecture 2 Slides Interfaces_.pdf
 
PMI TAMIZHAGAM - A PMI CHENNAI CHAPTER'S NEWSLETTER - Q1FY24.pdf
PMI TAMIZHAGAM - A PMI CHENNAI CHAPTER'S NEWSLETTER - Q1FY24.pdfPMI TAMIZHAGAM - A PMI CHENNAI CHAPTER'S NEWSLETTER - Q1FY24.pdf
PMI TAMIZHAGAM - A PMI CHENNAI CHAPTER'S NEWSLETTER - Q1FY24.pdf
 
Genetics, Heredity, Variation, history, its roles, Scope, Importance, and Bra...
Genetics, Heredity, Variation, history, its roles, Scope, Importance, and Bra...Genetics, Heredity, Variation, history, its roles, Scope, Importance, and Bra...
Genetics, Heredity, Variation, history, its roles, Scope, Importance, and Bra...
 
2024-02-24_Session 1 - PMLE_UPDATED.pptx
2024-02-24_Session 1 - PMLE_UPDATED.pptx2024-02-24_Session 1 - PMLE_UPDATED.pptx
2024-02-24_Session 1 - PMLE_UPDATED.pptx
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
A Free eBook ~ Mental Exercise ...Puzzles to Analyze.pdf
A Free eBook ~ Mental Exercise ...Puzzles to Analyze.pdfA Free eBook ~ Mental Exercise ...Puzzles to Analyze.pdf
A Free eBook ~ Mental Exercise ...Puzzles to Analyze.pdf
 
Relational_Algebra_Calculus Operations.pdf
Relational_Algebra_Calculus Operations.pdfRelational_Algebra_Calculus Operations.pdf
Relational_Algebra_Calculus Operations.pdf
 
天橋立 観光メモ 2024-30-302-2-Amanohashidate Sightseeing Memo.pptx
天橋立 観光メモ 2024-30-302-2-Amanohashidate Sightseeing Memo.pptx天橋立 観光メモ 2024-30-302-2-Amanohashidate Sightseeing Memo.pptx
天橋立 観光メモ 2024-30-302-2-Amanohashidate Sightseeing Memo.pptx
 
Organic Synthesis and Estimation of Functional Groups
Organic Synthesis and Estimation of Functional GroupsOrganic Synthesis and Estimation of Functional Groups
Organic Synthesis and Estimation of Functional Groups
 
Capitol Doctoral Presentation -Feb 2024.pptx
Capitol Doctoral Presentation -Feb 2024.pptxCapitol Doctoral Presentation -Feb 2024.pptx
Capitol Doctoral Presentation -Feb 2024.pptx
 
Discussing the new Competence Framework for project managers in the built env...
Discussing the new Competence Framework for project managers in the built env...Discussing the new Competence Framework for project managers in the built env...
Discussing the new Competence Framework for project managers in the built env...
 
Practical Research 1, Lesson 5: DESIGNING A RESEARCH PROJECT RELATED TO DAILY...
Practical Research 1, Lesson 5: DESIGNING A RESEARCH PROJECT RELATED TO DAILY...Practical Research 1, Lesson 5: DESIGNING A RESEARCH PROJECT RELATED TO DAILY...
Practical Research 1, Lesson 5: DESIGNING A RESEARCH PROJECT RELATED TO DAILY...
 
Mycology Update February 2024 Microbes with Morgan
Mycology Update February 2024 Microbes with MorganMycology Update February 2024 Microbes with Morgan
Mycology Update February 2024 Microbes with Morgan
 
Kartik Nair In Media Res Media Component
Kartik Nair In Media Res Media ComponentKartik Nair In Media Res Media Component
Kartik Nair In Media Res Media Component
 

Using JAVA There is very deep and strong river and the only way one pe.docx

  • 1. Using JAVA There is very deep and strong river and the only way one person can cross the river is to jump on the stones. There are N-1 stones on river from one side to another, placed in equal distances. If we give numbers to stones, we have 1, 2, 3,...,N-1 and the other side of the river can be numbered as N. A person can only jump to stone infront of him, or to the next one or to the next next one, but not longer. In other words, one possibility to cross the river is: {1, 2, 3,..., N}, another possibility is: { 3, 4,..., N} and another one is {3,6,9,.., N}, and so on. Design and implement an algorihtm to print number of possibilities and all possible paths to cross the river, when n is given. For example; when n=4 is given, it should print these lines to the screen: Pseudocode for your algorithm. Your Java file that implements the algorithm. Output files of your running program for three different n values: n=6, n=7, and n=8. Solution java code public class RiverCrossing { private int noOfways; public void noOfWaysToCross(int n){ int f1=1,f2=2,f3=0; noOfways=0; while(f3<=n){ f3=f1+f2; noOfways+=f3; f1=f2; f2=f3; } System.out.println("No. of ways to cross the river: "+noOfways); } public static void main(String[] args) { RiverCrossing r=new RiverCrossing(); r.noOfWaysToCross(6); r.noOfWaysToCross(7); r.noOfWaysToCross(8); } }