473,404 Members | 2,187 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Displaying a string

36
here is my code i dont understand why it doesnt print me anything.....
Expand|Select|Wrap|Line Numbers
  1. class StringDemo
  2. {
  3. public static void main(String[] args)
  4. {
  5. String s1,s2,s3,output;
  6.  
  7. s1=new String("hello");
  8. s2=new String("hello guys");
  9. s3=new String("happy birthday");
  10.  
  11. output="s1 = " +s1+ "\ns2 = " +s2+  "\ns3" +s3+;
  12.  
  13. }
help me not getting s1,s2,s3
Apr 4 '10 #1

✓ answered by justwantananswer

You code just created four String objects and did nothing more. If you want to print something, you need to use System.out.println(). i.e.

System.out.println(ouput);

By the way, do not write the following code:

s1 = new String("hello");

Although it works, it is not a good practice. Just write the following is enough:

s1 = "hello";

Try to read articles about "immutable", "string constant", etc.

3 1662
You code just created four String objects and did nothing more. If you want to print something, you need to use System.out.println(). i.e.

System.out.println(ouput);

By the way, do not write the following code:

s1 = new String("hello");

Although it works, it is not a good practice. Just write the following is enough:

s1 = "hello";

Try to read articles about "immutable", "string constant", etc.
Apr 4 '10 #2
ahmee
36
i also use system.out.println method but it give error that + operator not recognized
Apr 4 '10 #3
rethab
3
the last character on the line where you initialize 'output' is a +. remove it!
Apr 4 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Dave Posh | last post by:
I seem to be having a problem displaying time stored in mysql. The format stored in the database is 13:15:05. The database data type is time. I'm using asp vbscript and sql to retrieve the time...
0
by: Fronky | last post by:
Hope someone can help. I am still learning, so no laughing please. I am displaying records from a database using Response.Write(""); instead of the usual datagrid method. I am doing it this way...
1
by: asad | last post by:
hello how ru all, i have some problem in displaying xml file in asp.net, i successfully create an xml file but when want to display it through ASP.NET code it throwing following error. ...
0
by: Phil G. | last post by:
Hi, my 'project' requires that I create a form with text info. at set time periods. These time periods are not evenly spaced so I pass a param for the delay(seconds). In order to debug this I have...
5
by: Bill | last post by:
Hello, Could anyone post some simple code or advise me on how I can display the SSN number like *****7890 in a text box, even thought the user entered 1234567890, and the value of the variable...
11
by: prats | last post by:
I want to write a GUI application in PYTHON using QT. This application is supposed to take in Japanese characters. I am using PyQt as the wrapper for using QT from python. I am able to take input...
2
by: mazdotnet | last post by:
Hi, I have the following code in the code-behind file public string section; section = Request.ToString() and I like to display it in my .aspx page (included .ascx) but it's not working.
7
by: Jonathan Wood | last post by:
Okay, I have a site that displays information based on user input, a couple of the items are plain strings that the user entered. I understand the risk here is that they could insert javascript...
2
by: Garima12 | last post by:
I am writing following code to fetch the data from database, using stored procedure. problem is it is highlighting ByVal and when I mouse over, it is displaying expression expected. Please anyone...
10
by: =?iso-8859-1?B?S2VyZW0gR/xtcvxrY/w=?= | last post by:
Hi, i have text like this: "ACPI\GENUINEINTEL_-_X86_FAMILY_6_MODEL_13\_0" an after displaying it in a RichTextBox as RTF string, i get this: "ACPI_-_x86_Family_6_Model_13 "
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.