• Post Reply Bookmark Topic Watch Topic
  • New Topic

Sequence Generator  RSS feed

 
Ken Curtis
Greenhorn
Posts: 1
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I have only written a couple of simple programs to date, and have been assigned to write the following program, and to be honest I haven't even got a clue where to start.
Can anybody help me please.

The program that asks the user to input two input values. The output is supposed to be:
Run 1
Please enter an integer value 3
Please enter an integer value 6
All even integers from 3 to 6 are 4, 6
All odd integer values from 6 down are 5 3
All integers from 3 to 6 are 3 4 5 6

Run 2
Please enter an integer value 9
Please enter an integer value 5
All even integers from 6 to 9 are 6 8
All odd integer values from 9 down to 5 are 9 7 5
All integers from 5 to 9 are 5 6 7 8

run 3
please enter an integer value 3
please enter an integer value -2
All even integers from -2 to 3 are -2 0 2
All odd integers from 3 down to -2 are 3 1 -1
All integers from -2 to 3 are -2 -1 0 1 2 3
 
subodh kureel
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello ,

Try using basic java APIs like java.util.Scanner , java.io.Console and formulae to find even and odd number.

 
Campbell Ritchie
Marshal
Posts: 56562
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

How far have you got and where are you stuck?
 
Liutauras Vilda
Sheriff
Posts: 4923
334
BSD
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
subodh kureel wrote:Try using basic java APIs like java.util.Scanner , java.io.Console and formulae to find even and odd number.


It seems more simpler approach is needed over here. I think about pencil and piece of paper. Nothing else couldn't be more useful solving this problem.


Ken, did you come up with an idea?
Please be kindly and post it here what you got so far, so we could look at and point you to a right direction.

But if still struggling with a start, then at least post your thoughts, how you think you should solve it.
What differences do you see from Run 1 output: 4, 6 and 3, 5 < what these numbers tells you? what common do they have and how do they differ from each other?


 
Sreerang Kulkarni
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wrote the below code for run1 and can extend to others:

import java.util.Scanner;

public class ImprovedSequenceGenerator {
//solution removed
}


Output:

Please enter an integer value 3
Please enter an integer value 6
All even integers from 3 to 6 are 4,6
All odd integer values from 6 down are 3 5
All integers from 3 to 6 are 3 4 5 6
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!