Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 09-12-2005, 03:38 PM   #1
Registered: Sep 2004
Location: Laredo, TX
Distribution: Slackware 11.0 [both lap & pc] WinXP
Posts: 164

Rep: Reputation: 30
Java Problem on trim command

i have a problem here, and i dont know why i keep gettin it wrong, in the following code, i figured id get this output: 0246

public class Class1 {

	public static void main(String[] args) {
	String s="";
	int k=0;
	while (k<=6)
		s = s.trim() + Integer.toString(k);
		if (k%2 ==1)
		k = Integer.parseInt(s);
when i run and compile, instead of getting what i thought, i get a 246 what i really dont get is if i put the

		s = s.trim() + Integer.toString(k);
before anything else, what happens to the zero?
Old 09-12-2005, 03:45 PM   #2
Registered: Dec 2004
Location: Northern CA
Distribution: Mepis 6.5
Posts: 123

Rep: Reputation: 15
k is an Int. An int value does not have leading zeroes. So when you Int.Parse a "02" string, it becomes "2".

I may have missed something specific in your code that you're doing, but that's the short answer.
Old 09-12-2005, 03:49 PM   #3
Registered: Sep 2004
Location: Laredo, TX
Distribution: Slackware 11.0 [both lap & pc] WinXP
Posts: 164

Original Poster
Rep: Reputation: 30
thanx i did not know that, appreciate the help


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
trim a line schneidz Programming 2 10-07-2005 06:47 PM
Problem executing this piped command: JAVA randomx Programming 1 07-16-2004 07:39 PM
How to Trim mpeg video's ? qwijibow Linux - Software 1 01-06-2004 08:28 PM
How can I safely trim down /dev ? tigermusti Linux - General 9 12-12-2002 04:33 PM
java command - "bash: java: command not found" ??? RedHat123 Programming 2 07-16-2002 11:09 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:16 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration