printout


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

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:-)

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


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center