DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 4 of 4

Thread: printout

  1. #1
    Join Date
    Oct 2002
    Posts
    5

    printout

    can anyone help me with how to print out an answer one digit at a time
    thanks
    henry

  2. #2
    Join Date
    Mar 2003
    Posts
    834
    Could you be a little bit more specific? Post some code.

    You should probably convert your answer to a String and then loop through each character.
    ArchAngel.
    O:-)

  3. #3
    Join Date
    Oct 2002
    Posts
    5

    printout

    thanks ArchAngel

    I'm just trying to get used to inputing any number the now and printing it out eventually I will be trying to printout from a stack

    Code:
    import java.io.*;
    public class Printout
    {
    	static BufferedReader keyboard = new
    		BufferedReader(new InputStreamReader(System.in));
    
    		  // For screen output
    	  static PrintWriter screen = new PrintWriter(System.out, true);
    
    public static void main(String[]args)throws IOException
    	{
    		int element,n;
    
    				screen.println("Please enter your number ");
    				element = new Integer(keyboard.readLine()).intValue();
    				screen.flush();
    				n = element;
    
    				{
    
    				if (n<=10)
    				screen.println(n/10);
    				screen.println(n % 10);
    
    				}
    		}
    }
    cheers
    Henry

    [ArchAngel added CODE tags]

  4. #4
    Join Date
    Mar 2003
    Posts
    834
    Here's the more usual way to read in a number, display it and then convert it to an int:
    Code:
    import java.io.*;
    
    public class Printout {
    
            public static void main(String[]args) throws IOException {
                    BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
    
                    System.out.print("Please enter your number: ");
                    String strInput = keyboard.readLine();
                    System.out.println("You entered: " + strInput);
    
                    // Convert to an int
                    int iInput = Integer.parseInt(strInput);
            }
    }
    ArchAngel.
    O:-)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links