Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Counter program for java
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


aerodeus
Counter program for java
2 Answer(s)      2 years and 5 months ago
Posted in : Java Beginners


The problem is to count from 000 to 444 with recursion. The maximum digit is 4 so that the program will count from 000,001,002,003,004,010, 011 and so on. How can I solve this?


Advertisement
View Answers

May 8, 2012 at 5:15 PM


The given code create a recursive function to count numbers from 000 to 444 as string. The maximum digit is 4.

import java.util.*;
class PrintNumbers 
{
    static public void findNumbers(String[] array, List<String> list, String st, int depth) {
        if (st.length() >= depth)
           return;
        for (String s : array) {
            String str=st+s;
            list.add(str);
            findNumbers(array, list, str, depth);
        }
        for (int i=0; i<list.size(); i++){
        if(list.get(i).length()<3){
            list.remove(i);  
        }
      }
    }
    public static void main(String[] args) {
        String[] numbers = {"0", "1", "2", "3", "4"};
        ArrayList<String> list = new ArrayList<String>();
        findNumbers(numbers, list, "", 3);
        System.out.println(list);
    }
}


May 9, 2012 at 1:00 AM


Thanks a lot.... Really appreciate...



Related Tutorials/Questions & Answers:
Counter program for java
Counter program for java  The problem is to count from 000 to 444 with recursion. The maximum digit is 4 so that the program will count from 000,001,002,003,004,010, 011 and so on. How can I solve
character counter - Java Beginners
of the entered(by user) name?  hy katy, import java.io.*; class counter { public counter() { System.out.print("Enter ur name:"); try... void main(String args[]) { new counter(); } } this code
Advertisements
Hit Counter Schema using java script - WebSevices
Hit Counter Schema using java script   Dear Sir, I am sending you none project i need you help please tell me how to do it? first I have... counter of 0-9 and then switch to an alphabet for 10 and above. After going over
Create a counter in mySQL 5 database through Java - SQL
Create a counter in mySQL 5 database through Java  Dear Editor, Thanks for your valuable Java code example for JFileChooser. I had another question regarding Java & mySQL 5 database
Servlet Counter
{ int counter = 0; public void doGet(HttpServletRequest request...(); counter++; pw.println("At present the value of the counter is " + counter); } } In the above example, which keeps track how many times the servlet
SHOPPING COUNTER
the java. thanks for helps.   Hi Friend, Try the following code
Simple Counter In Servlet
a program on counter which will keep track how many times the servlet has been...;counter);   } } The output of the program... Simple Counter in Servlet     
counter - JSP-Interview Questions
using java technology,i explained we can do that by using jsp and servlets...********///////// A page with a counter This page has been visited: times. This counter never increases its value
Java Program - Java Beginners
Java Program  Write a program that demonstrates the use... threads should represent the counters as follows : 1) One counter starts from 5 and increments with the step of 5. 2) Second counter starts from 10
Java Program - Java Beginners
Java Program  Write a program that demonstrates the use... threads should represent the counters as follows : 1) One counter starts from 5 and increments with the step of 5. 2) Second counter starts from 10
java main program
java main program  how to write a main program for the following code...++) { //Look backward int counter = 0; while(counter <= mRange && i >= 0 && counter <= i
Threading in Java
, program counter and lifetime.   Life Cycle of A Thread... Threading in Java      ... is very important in Java Programing language. A thread is a sequential path
Using Bean Counter in JSP
Using Bean Counter in JSP       In this section you will learn how the counter bean can be used in jsp. As you all know a counter increments the value by one. Here, we will use
java program for
java program for   java program for printing documents,images and cards
java program - Java Beginners
it will b cleared.the program should b done onlu using java applet but not with swing...java program  there are two buttons-one for "show" and the other...(); int f1, f2 = 0, f3 = 1; int counter=0; int num=10; String n
Java Program - Java Beginners
Java Program  The numbers in the following sequence are called... a program using do‚?¶..while loop to calculate and print the first m Fibonacci numbers...: public class FibonacciSeries { int counter=0; public void generateSeries(int num
Java Program
Java Program  A Java Program that print the data on the printer but buttons not to be printed
a Java program
a Java program    Write a Java program to print even numbers from 2 to 1024? Write a Java program to print ? My Name is Mirza? 100 times? Write a Java program to print Fibonacci Series? Write a Java program to reverse a number
Java Program - Java Beginners
Java Program  Write a program that prints prime numbers between 1 to n. Number n should be acepted as command line input.  Hi Friend... = ""; int counter = 0; System.out.println("Prime Numbers between 1 to "+num
java program
java program  write a program to print 1234 567 89 10
Java Program - Java Beginners
Java Program  Write a program that detects successive repeated occurrence of a letter in a word. For example, in the word ‚??explanation‚?? letter ‚...(" ", ""); char[]third =st.toCharArray(); for(int counter =0;counter=0
java program
java program  Write a java program to do matrix addition operation On two given matrices
java program
java program  Write a java program to find the number of Positive numbers in m* n matrix
java program
java program  Write a program to create an applet and display The message "welcome to java
java program
java program  java program to implement the reflection of a particular class details like constructor,methods and fields with its modifiers
Java Program
Java Program  java program to insert row in excel sheet after identifying an object
java program
java program  write a java program to display array list and calculate the average of given array
java program
java program  write a java program to display array list and calculate the average of given array
java program
java program  write java program for constructor,overriding,overriding,exception handling
java program
java program  how to write an addition program in java without using arithematic operator
Advertisements
 

 

 

DMCA.com