473,472 Members | 1,761 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

system.out.println()

9 New Member
hello
i am just a beginner of java but iwant know if i can declare a variable of any datatype and output its value simaltaneously using sytem.out.println()
if no ihave another doubt
how this is possible
for(int i=0;i<10;i++);
please tell me
hanks in advance
Jan 22 '08 #1
6 2967
Laharl
849 Recognized Expert Contributor
Assuming you're working with primitives (int, double, boolean, etc), this is as simple as putting the value in System.out.println().

Expand|Select|Wrap|Line Numbers
  1. System.out.println(4); //Should print 4
  2.  
For objects, if the toString() is defined, you can call an unnamed constructor in System.out.println() and print that way.

Expand|Select|Wrap|Line Numbers
  1. System.out.println(new Integer(4)); //Prints 4
  2.  
As to your loop question, that works because the for loop is a builtin Java construct that works with that syntax. I'm not sure how else to explain this to you...
Jan 22 '08 #2
hoggy
9 New Member
thanks
but
can i write
system.out.println(int num=10 +num)?
num is not declared anywhere before this statement in the program
Jan 22 '08 #3
BigDaddyLH
1,216 Recognized Expert Top Contributor
hello
i am just a beginner of Java but i want know if i can declare a variable of any datatype and output its value using Sytem.out.println()
Tip: bookmark the API and learn to look things up there: http://java.sun.com/javase/6/docs/api/

Using it you would see that System.out is of type System.out.PrintStream
And that println is overridden to take a boolean, car, char[], double, float, int, long, String or Object. So pass it anything, but realize that if you are using the Object version and passing it a non-null reference, it will use the object toString method, which may or may not be what you want.

More generally, why not just try it and see what happens? It's faster that posting a question in the forum.

how this is possible
for(int i=0;i<10;i++);
please tell me
hanks in advance
I don't understand your question. Are you asking why that is legal syntax? It's beacuse of the empty statement.
Jan 22 '08 #4
BigDaddyLH
1,216 Recognized Expert Top Contributor
thanks
but
can i write
system.out.println(int num=10 +num)?
The best way to find out is to try it and see.
Jan 22 '08 #5
hoggy
9 New Member
have u tried the print statement before if not please try it and tell me please dont mind
and about the loop statement
if i write
for(int i=0;i<10;i++)
{
sytem.out.println("i is" +i);
}
it is possible in c++ bcoz there is no restriction that variables must be daeclared all at once it follows bottom to top approach then my line
system.out.println must be right please tellme
.good night
Jan 22 '08 #6
BigDaddyLH
1,216 Recognized Expert Top Contributor
have u tried the print statement before if not please try it and tell me please dont mind
and about the loop statement
if i write
for(int i=0;i<10;i++)
{
sytem.out.println("i is" +i);
}
it is possible in c++ bcoz there is no restriction that variables must be daeclared all at once it follows bottom to top approach then my line
system.out.println must be right please tellme
.good night
Don't post "can I do this" posts. Just try it and see. If you don't have access to a compiler at the moment, then wait until you can compile it.
Jan 22 '08 #7

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

Similar topics

3
by: vishnu mahendra | last post by:
Hello to all, Can you give me the code so that i can make sure that my system is connected to the internet. thank you in advance, vishnu
4
by: FilexBB | last post by:
Hi Folks, I have tried to redirect system.out for a while and then set it back, but it can't set it back as following program snapshot ByteArrayOutputStream baos = new ByteArrayOutputStream();...
2
by: Your Friend | last post by:
Hello All, I'm relatively new to Python programming but have been working on this problem for a little bit now ... I initially began writing UNIX scripts in Python and thought it was the...
1
by: sylsau | last post by:
Hello, I wrote a JAVA program which uses the JAVA API JDOM 1.0 (of this site www.jdom.org) I put the archive jdom.jar in the directory /usr/share/java/jdom.jar and I added this path in the...
1
by: keke3905 | last post by:
I really would appreciate some help on this assignment. I need to make GUI boxes to display the system info such as on Microsoft Office. I have some code but not sure where to go with the rest of...
2
by: astolpho | last post by:
I am using a slightly outdated reference book on J2EE programming. It gives 2 methods of creating a database used in its casestudies. The first is an ANT script that gives the following output: ...
0
by: Pavithra MK | last post by:
Hi all, i am working on a webserver, i am facing a problem in this, while running a servlet which includes System.out.println() and System.err(). In the webserver two files are there in log...
1
by: Pavithra MK | last post by:
Hi, I am working on a webserver, i am facing a problem in this, while running a servlet which includes System.out.println() and System.err(). In the webserver two files are there in log directory...
7
hsn
by: hsn | last post by:
hello everyone. i am trying to use the system.setproperty to set the proxy in my computer. public static void main(String args) { // TODO Auto-generated method stub ...
0
by: netri | last post by:
I need to write a java program in which i need to access a computer in my network using IP address but system is password protected.so how can i access a password protected system to fetch a file...
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
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...
1
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
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.