Computers & Internet Logo

Related Topics:

Posted on Mar 26, 2010
Answered by a Fixya Expert

Trustworthy Expert Solutions

At Fixya.com, our trusted experts are meticulously vetted and possess extensive experience in their respective fields. Backed by a community of knowledgeable professionals, our platform ensures that the solutions provided are thoroughly researched and validated.

View Our Top Experts

JavaBat.Com i need to count the number of ''7''s in a digit using recursion. How do i do that?? :)

1 Answer

Anonymous

Level 3:

An expert who has achieved level 3 by getting 1000 points

All-Star:

An expert that got 10 achievements.

MVP:

An expert that got 5 achievements.

Brigadier General:

An expert that has over 10,000 points.

  • Master 10,406 Answers
  • Posted on Mar 26, 2010
Anonymous
Master
Level 3:

An expert who has achieved level 3 by getting 1000 points

All-Star:

An expert that got 10 achievements.

MVP:

An expert that got 5 achievements.

Brigadier General:

An expert that has over 10,000 points.

Joined: Apr 23, 2009
Answers
10406
Questions
1
Helped
2557353
Points
31058

/* REXX is better than JAVA */
input = '17273747'
x = count7(input)
say 'number of "7" characters is:' x
exit

count7: parse arg digit 2 tail
if digit = ' ' then return(0)
match = (digit = '7')
return (match + count7(tail))

i.e., split the "input" into the 1st column and the "tail" (the other columns).
If there is no "first" column, return '0' ("none").
Test the 1st column.
Recursively call the function, passing the "second-through-last" columns, adding-in the result (0 or 1) from the 1st column.

Add Your Answer

×

Uploading: 0%

my-video-file.mp4

Complete. Click "Add" to insert your video. Add

×

Loading...
Loading...

Related Questions:

1helpful
1answer

I want a calc that has a space for me to type in a sum

What kind of sum would that be? If it is a sum of a certain number of values that are explicitly given (2+5.5+ 16...) just enter them one after the other separated by the operator (+).
For a sum of terms that are defined by some recursion fornula then you will need a calculator with a Computer Algebra System (TI Nspire CAS, TI 92PLUS, TI Voyage 200 PLT, Casio ClassPad, HP 40G/49 G+/50G..)
A TI 83PLUS/84PLUS may be able to handle numerical sums of terms defined recursively.
0helpful
5answers

Plustron lcd TV/DVD NEED CODE

Hello,

Try this solution posted by Ipsita: http://www.videohelp.com/dvdhacks/coby-tf-dvd7006/8694

thank you to IPsita if this work:

The contain below:

icon_minipost.gifRegion code hack posted by ipsita, January 11 2008:
1) Remove the dvd (if present) from the player
2) Open the tray
3) Press STOP on the remote
4) Press 7 0 on the remote
5) Press MENU on the remote
6) You can see the current region on the top of the screen
7) Press the appropriate region code, e.g. press 5 if the region code needs to be Russia. Press 0 to make the dvd player region free.
8) Press MENU

melnavz
7helpful
1answer

Lost instructions for photocell Type:ET321

Here is how it works. The push button repeats itself in following sequence (must plug in).
F 1 2 3 4 5 6 7 8 9 A d 1. 2. 3. 4. 5. 6. 7. 8. 9.

F: timer is off.
1 2 3 4 5 6 7 8 9: from dusk to dawn count down number of hours repeated every day. That's most useful to control outdoor lightings.
A: from dusk to dawn count down number of hours which is randomly selected by this timer. Which is usually for indoor use to turn lights on and off for number of hours. The randomly selected hours is a security feature so that lights on (on from dust, but off randomly) time shows no pattern to outsiders.
d: just on from dusk and off at dawn. It is also used to control outside lights but just a little wasteful in my opinion.
1. 2. 3. 4. 5. 6. 7. 8. 9.: meaning count down number of hours starts from the time when the button is pushed so that you can have a countdown timer at any time.
1helpful
1answer

I need help with significant figures 3.414s 10.02s 58.325s 0.00098s

There are 4 sig figs (sfs) in 3.414.
Also,
  • 4 sfs in 10.02
  • 5 sfs in 58.325
  • 2 sfs in 0.00098

The rule I use is the "dot right-moving arrow" rule.
I know it seems weird, but it is a very powerful rule, always reliable!

Here is what you do:
If the number has a dot in it (that is, if it has a decimal in it), imagine an arrow swooshing from left to right through the number. Start counting sig figs as soon as the imaginary arrow strikes a non-zero digit. Every digit the arrow goes through after it hits that first non-zero digit, is a significant digit (sig fig). The total number of sig figs is the sum of the first non-zero digit + all the following digits the arrow goes through after that. Very simple, right?

As an example, in 0.00098, the arrow sweeps through the leading zeros without counting until it stikes the first nonzero digit, 9. (BONK!!) So you must count it and the following digit (8). So the total number of sfs is only 2 for this number. Try it on the other numbers for practice.

For a better closure, I guess I should explain the other related rule for sig figs:
The "no-dot left arrow" rule. You can use this rule when a number does not have a decimal in it. For example, the number 500 s. (I am using the same unit you gave in your quantities. As you can see, no decimal is shown. So you can not be sure the number has 3 sfs or not. It would only have 3 sig figs if you were informed it was an exact number. An exact number is a number which has been obtained by counting every object it represents. As in a classroom filled with 200 students, each one counted by their teacher during roll call.

To apply the no-dot left-moving arrow rule, simply imagine an arrow moving left until it hits the first non-zero digit. In this case, that digit is the 5, which is only one digit. Therefore, there is only 1 sig fig in 500 s.

Suggestion: Google up "sig figs" and get some more examples of quantities to practice counting sig figs. Also pay attention to the important related topic of proper rounding off of calculated quantities which have different numbers of sig figs. You will find this skill invaluable when you take a lab based chemistry or physics course!

Good luck!

###
6helpful
1answer

I am looking for a download link for the First Alert ET321 with photocell. I have misplaced the original package instructions and cannot find this material anywhere! Your assistance would be greatly...

Here is how it works. The push button repeats itself in following sequence (must plug in). F 1 2 3 4 5 6 7 8 9 A d 1. 2. 3. 4. 5. 6. 7. 8. 9.
F: timer is off. 1 2 3 4 5 6 7 8 9: from dusk to dawn count down number of hours repeated every day. That's most useful to control outdoor lightings. A: from dusk to dawn count down number of hours which is randomly selected by this timer. Which is usually for indoor use to turn lights on and off for number of hours. The randomly selected hours is a security feature so that lights on (I believe the on time is within the range of 1 hour from dusk set by the timer) and off (it is randomly set, you can see the display blinking showing the selected countdown hours) shows no pattern to outsiders. d: just on from dusk and off at dawn. It is also used to control outside lights but just a little wasteful in my opinion. 1. 2. 3. 4. 5. 6. 7. 8. 9.: meaning count down number of hours starts from the time when the button is pushed so that you can have a countdown timer at any time.
9helpful
1answer

Instruction for first alert et321 timer

Here is how it works. The push button repeats itself in following sequence (must plug in).
F 1 2 3 4 5 6 7 8 9 A d 1. 2. 3. 4. 5. 6. 7. 8. 9.

F: timer is off.
1 2 3 4 5 6 7 8 9: from dusk to dawn count down number of hours repeated every day. That's most useful to control outdoor lightings.
A: from dusk to dawn count down number of hours which is randomly selected by this timer. Which is usually for indoor use to turn lights on and off for number of hours. The randomly selected hours is a security feature so that lights on (on from dust, but off randomly) time shows no pattern to outsiders.
d: just on from dusk and off at dawn. It is also used to control outside lights but just a little wasteful in my opinion.
1. 2. 3. 4. 5. 6. 7. 8. 9.: meaning count down number of hours starts from the time when the button is pushed so that you can have a countdown timer at any time.
1helpful
1answer

How do i fix stack overflow on line 144

A stack overflowis caused by recursion. You have an area of reserved memory called the stack when you call a function which calls itself you have what is called recursion.

If the recursive loop never ends you will run out of memory and get a stack overflow error.

If it is code you have written then check your code for recursion and replace with a while loop <- you can only use while loops

If the code was written by someone else - such as a website then inform the webmaster@ whatever domain name they have and hope they fix the problem soon.

If this helped you, then please help me and vote kindly
0helpful
1answer

HOW TO USE text.formatDouble in java

You can use these calls:

formatDouble(double inVal, int inDecs, int inLeftOfDec)
formatDouble(double inVal, int inDecs, int inLeftOfDec, boolean recursing)

inVal - double number to be formatted
inDecs - minimum significant figures
inLeftOfDec - number of fixed decimals

As far as I remember java, you use it like this:
String s;
s.formatDouble(34.5566, 2, 3);
0helpful
1answer

Input a number and then show the fibonacci sequence of the input number in a C++ program.

I'm assuming one of two things, either

A) You need help for a programming class?

or

B) You're just curious?

Either way

#include <iostream>
#include <algorithm>
using std::swap;
using std::cout;
using std::endl;
// Function f returns n'th Fibonacci number
// It uses Algorithm 2C: non-recursive loop
unsigned int f(unsigned int x) {
unsigned int x1=1;
for(unsigned int i=1,x2=1;i<=x;i++) {
x1+=x2;
swap(x1,x2);
}
return x1;
}
// Function f_print prints out n'th Fibonacci number
void f_print(int n) {
cout << n << "th Fibonacci number is " << f(n) << endl;
}
// main is the entry point in C++
int main() {
f_print(46);
}

0helpful
1answer

Code for prime numbers in c

Prime numbers can be calculated by using recursive algorithm
int i,j=1;
i++;
for (j=2;j<i;j++)
{
If (i%j==0)printf(" %d number is prime",&i );
else printf(" %d number is not prime",&i);
i++;
delay(20);
}
Ctrl break to terminate execution or other
Not finding what you are looking for?

162 views

Ask a Question

Usually answered in minutes!

Top Sun Computers & Internet Experts

Rob Hill
Rob Hill

Level 3 Expert

1480 Answers

k24674

Level 3 Expert

8093 Answers

Sean Wright
Sean Wright

Level 3 Expert

2045 Answers

Are you a Sun Computer and Internet Expert? Answer questions, earn points and help others

Answer questions

Manuals & User Guides

Loading...