• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to code this?  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
problem 1:
note: please don't use array and file handling here

1. Write a program that prompts the user to input an integer and then outputs both the individual digits of the number and the sum of the digits . For example, the program should: output the individual digits of 2345526 as 2 3 4 5 5 2 6; output the individual digits of 4000 as 4 0 0 0; and output the individual digits of -2345 as 2 3 4 5.

2. Write a program that prompts the user to input an integer and then outputs the number with the digits reversed. For example, if the input is 12345, the output should be 54321. Your program must also output 5000 as 0005 and 980 as 089.

Problem 2:
Note: please use array here just don't use file handling.

1. Write a program that reads a file consisting of students test scores in the range 0-200. it should then determine the number of students having scores in each of the following ranges: 0-24, 25-49, 50-74, 75-99, 100-124, 125-149, 150-174, and 175-200. output the score ranges and the number of students having scores in each of the following input data: 76, 89, 150, 135, 200,76, 12, 100, 150, 28, 178, 189, 167, 200, 175, 150, 87, 99, 129, 149, 176, 200, 87, 35, 157, 189

add: for problem 1. numbers 1 - 2
please use also either of the following:
*counter-controlled while loops
*Sentinel-controlled while loops
*Flag-controlled while loops
*EOF-controlled while loops
 
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glenn Kaiser wrote:problem 1...

First: Welcome to JavaRanch, Glenn.

Next: Is there a question here? I'm afraid we're NotACodeMill (←click), so nobody's going to simply write the programs for you. You need to ShowSomeEffort (←click) - and a good demonstration of that would be to show us what you've tried; maybe for one problem at a time. Then we'll be happy to deal with any specific questions you have about something you don't understand.

Winston
 
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch, Glenn.

We're not going to write the code for you. Please try it yourself first, and if you have specific problems, then please show us your code and explain where you are stuck.

Before writing any code though, take a moment to think through exactly what the program has to do and how it's going to do it. You must have a plan for how the program is going to work before you can write it down in code. Take a pencil and paper and write down (in normal language) what steps the program has to follow.
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Regarding problem 1, try taking in the number as a string.
Then there are all sorts of things you can do with strings, including reversing it (built in methods).
Include checks on the string on each character and ignore anything other than a number.
Then when you find a number add it to sum which is initialised as zero.
What you need to do is read up on strings and their associated methods and you'll be fine.

Try this first and complete it before looking at problem 2.
 
Marshal
Posts: 56608
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't turn the number into a String. Are you supposed to enter the number as a command‑line argument (somebody else had to do that today: here) or an an int? You know there are classes which can turn what you write on the keyboard into an int directly?

Forget about individual digits. Write a method which reads an int, and call it from another method which displays it:-I personally would put that sort of method into a utility class, but you might not have time to write a utility class. Get that working, then you will know how to get the number. Then you can think about individual digits. Or you can search this forum because somebody else is asking about individual digits.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!