Counter program for java

Ads

 
 
 

Share on Google+Share on Google+

aerodeus
Counter program for java
2 Answer(s)      5 years 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?

Ads
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...


Ads









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 - 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 for
java program for   java program for printing documents,images and cards
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
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
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 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
Tutorials   
Java Spring Hibernate Struts Training ClassNotFoundException HttpRequestInterceptor java.lang.noclassdeffounderror: org/apache/http/httprequest noclassdeffounderror: org/apache/http/client/methods/httpurirequest java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient How do I resolve this Java Class not found exception? httpclient java.lang.NoClassDefFoundError Apache Commons ioutils maven dependency Read/Convert an inputStream to a String What is the meaning of Java Platform? Why Java is a platform independent language? What is the benefits of learning Core Java? Which technology should I learn after Java? What is array in java with example? How to Convert ArrayList to Array? How to substring in Java? How to format number in Java? What is instance variable in Java? How to download MySQL JDBC driver? What is Calendar class in Java? Which is the best Java tutorials for beginners? How to rename a file in Java? How to delete file in Java code? How to get day from date in Java using Calendar? How to get day of week in Java? How to calculate Date Difference in Java? How to compare date in Java? How to declare array in Java? How to calculate average of array in Java? What is Array in Java? write a java program to find the summation of all the integers entered on command line Sum of two numbers using command line arguments in Java How to create and use Array in Java? How to pass command line arguments in Java? How to create Applet Hello World? Appending String efficiently in Java How to append String in Java? How to list even numbers between 1 and 100? How to add BigDecimal in Java? What is Abstraction In Java? Which is best Beginners Java Tutorial? What is java.util package? Create list from array in Java Filter collection in Java 8 What is the best way to filter a Java Collection? Easy way to transform Collection to Array? How to convert Collection to Array in Java? What are Basic Java Language Elements? Advanced Java Tutorials in 2017 Java brief history Best Reasons to learn Java

Ads

 
Advertisement null

Ads