LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 01-16-2002, 06:47 PM   #1
vicente
Member
 
Registered: Jul 2001
Location: Lx (Portugal)
Distribution: Mandrake workstation8.0,red hat 7.2 , peanut linux
Posts: 134

Rep: Reputation: 15
java


why can this give a for letter out put?

class Charte
{
public static void main(String args[])
{
char char1, char2, char3, char4;

char1 = 10;

char2 = 14;

char3 = 23;

char4 = 5;

System.out.print("my name: ");
System.out.println(char1 + char2 + " " + char3 + char4);
}
}
 
Old 01-17-2002, 12:46 PM   #2
Bert
Senior Member
 
Registered: Jul 2001
Location: 406292E 290755N
Distribution: GNU/Linux Slackware 8.1, Redhat 8.0, LFS 4.0
Posts: 1,004

Rep: Reputation: 46
concatenation

Jose, I'm not sure what you're asking and what you're trying to do.

Looking at your code, java does strange things when you use the + sign with Strings and chars and ints.

What output did you want?

Bert
 
Old 01-18-2002, 03:30 AM   #3
glj
Member
 
Registered: Jul 2001
Location: London
Distribution: RH 9
Posts: 151

Rep: Reputation: 30
To concatenate strings in Java should you not use the "."

i.e.
char1.char2." ".char3.char4

glj
 
Old 01-18-2002, 05:56 PM   #4
vicente
Member
 
Registered: Jul 2001
Location: Lx (Portugal)
Distribution: Mandrake workstation8.0,red hat 7.2 , peanut linux
Posts: 134

Original Poster
Rep: Reputation: 15
the out put i wanted was :jose . I was trying to use the unicode , i dont know much about unicode so i thought that thoses numbers was the number for those 4 letters but it didnīt work out with ("char1+" "+char2") it works with 4 chars i dont know if the problem is the numbers or the use of 4 chars?
 
Old 01-19-2002, 08:53 AM   #5
Bert
Senior Member
 
Registered: Jul 2001
Location: 406292E 290755N
Distribution: GNU/Linux Slackware 8.1, Redhat 8.0, LFS 4.0
Posts: 1,004

Rep: Reputation: 46
Unicode

Ah, ok.

From memory, what you are doing should work, but those numbers do not appear to be unicode values.
Have a look in the JDK1.3 directory and you'll find a demo applet which shows unicode values, select the appropriate ones from there and try again.
You would declare a type char like this

char char1 = 34c5; // 34c5 is not the real value - you need to check it yourself

type, name of type, assignment, then variable.

Concatenation is a fancy word for sticking two things together.
In java you use the + sign, although java does also use the dot notation to call a method,

like System.out.print calls the print method in the out class of the System superclass (I think).

Cymru am Byth // this is Welsh (I think).
 
Old 01-21-2002, 04:17 AM   #6
glj
Member
 
Registered: Jul 2001
Location: London
Distribution: RH 9
Posts: 151

Rep: Reputation: 30
Quote:
Cymru am Byth // this is Welsh (I think).
It's Welsh for "Wales forever".
 
Old 01-21-2002, 02:22 PM   #7
Bert
Senior Member
 
Registered: Jul 2001
Location: 406292E 290755N
Distribution: GNU/Linux Slackware 8.1, Redhat 8.0, LFS 4.0
Posts: 1,004

Rep: Reputation: 46
Actually I knew that one
 
Old 01-22-2002, 07:39 AM   #8
mtsinc
LQ Newbie
 
Registered: Jan 2002
Location: Jacksonville, FL
Distribution: RedHat
Posts: 26

Rep: Reputation: 16
Unicode in Java isn't as obvious as you might think. Sun has spent a lot of time making Java as locale-independent as possible. There's no such thing as:

char ch = char$(41)

in Java, because that assumes a particular encoding - not just ASCII or Unicode, where the number of bytes is different, but EBCDIC as well - EBCDIC is still very much alive and well, and IBM would just LOVE to sell you a mainframe where CICS runs with Java apps.

Try for something more like this:

public class Hi {
public static void main( String[] args ) {
byte[] hithere = new byte[2];
hithere[0] = 64 + 8;
hithere[1] = 64 + 9;
try {
String hiString = new String( hithere, "utf-8" );
System.out.println("I made a string: \"" + hiString + "\"");
} catch ( Exception ex ) {
System.out.println("Uh-oh! " + ex.getMessage() );
}
}
}

The arithmetic is because I was too lazy to count ASCII (UTF-8) on my fingers, so I let the compiler add it for me. If you want real Unicode, double the size of "hithere", set the even-numbered bytes to 0 (since Unicode is a 2-byte encoding extending ASCII) and use the encoding "UTF-16".

BTW, a good reasource for java questions is http://www.javaranch.com
 
  


Reply



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
Java plugin installed correctly for Firefox but not able to view any java applet tvn Linux - Software 10 04-15-2010 02:13 AM
Java Programming: Java Runtime Environment not found when trying to compile murbz Linux - Software 2 03-26-2009 03:04 AM
Web start java not working (java works fine) powadha Debian 5 06-05-2004 12:57 PM
Updated Java... now java apps dont work zidane2010 Linux - Software 6 05-04-2004 08:02 PM
2 Questions: java calling system commands? PERL vs Java? randomx Programming 28 11-28-2003 08:24 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:36 PM.

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