473,418 Members | 1,749 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,418 software developers and data experts.

i have a question?help me

36
here is my code below. i have question regarding my code.why we have taken "output" as string.is this because we have used concate sign in this expression
output+=value+""; in the code if not plz tell me why??


Expand|Select|Wrap|Line Numbers
  1. int value;
  2. String output="";
  3. for(int i=1; i <=10 ; i++)
  4. {
  5.   value= 1+(int)(6* Math.random());
  6.   output+=value+"";
  7.   if(i%2==0){
  8.     output+="\n";
  9.   }
  10. }
Aug 7 '10 #1
4 1102
TheServant
1,168 Expert 1GB
Yes. It looks like you are to print your output variable, and so it is easier to be a string.

I don't know what:
Expand|Select|Wrap|Line Numbers
  1. output+=value+"";
means? I don't think you can add an int to a string like that? I may be wrong, but have you considered using an Integer instead, which allows you to utilize the .toString method. Second point is the +""? Why would you need to add an empty string?

Just confirming that you know that with output as a string it just (as you say) concatinates the value to the string and doesn't actually add (mathematically) any values. If this is your goal, it makes sense that you declare it a String.
Aug 11 '10 #2
Frinavale
9,735 Expert Mod 8TB
What are you trying to do in your code?
Please explain it by writing the code out in words/sentences to explain what you are doing on each line.

I don't even think that code will compile.

I do not understand what your question is exactly either.

-Frinny
Aug 12 '10 #3
My guess is doing value+"" is someone's way of forcing value to be a string instead of an integer. What you can do is

Expand|Select|Wrap|Line Numbers
  1. output += Integer.toString(value)
Aug 12 '10 #4
Dheeraj Joshi
1,123 Expert 1GB
I don't even think that code will compile.
It compiles and runs properly.

My guess is doing value+"" is someone's way of forcing value to be a string instead of an integer. What you can do is
No it is not. If you are using + operator you need not to convert the non string value to string. The "" in OP's code has no significance.

Ok.

Expand|Select|Wrap|Line Numbers
  1. output+=value+"";
  2.  
is same as

Expand|Select|Wrap|Line Numbers
  1. output=output+value+""
  2.  
This is legal in Java. '+' operator can work between String and String,Integer,character,double,float.

'+' operator does convert the non string value into its corresponding string representation.

As far as OP's code is concerned i think OP want single string to store all the values with a new line character which is generated within that loop.

Regards
Dheeraj Joshi
Aug 13 '10 #5

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

Similar topics

6
by: Jack Smith | last post by:
Help needed on this question. Any help is appreciated. Thanks in advance. Given a binary string (i.e. a finite sequence of 0's and 1's) we choose any two digit substring 01 and replace it by a...
2
by: Chris | last post by:
Probably a very easy question for most of you guys out there but I simply can't get to figure out how to do this Suppose that I have an unknown number of items (A,B,C,etc...) and each item...
5
by: Steve | last post by:
Hello,I hope someone body in this forum can be of help.Suddenly, I cannot connect from my PC to our web server via Visual Interdev (v6). My colleagues can using the same login information. I can...
2
by: Simon Harvey | last post by:
Hi everyone, I have a question about how data is stored and persisted in a realworld application. I am currrently making an email client, newsreader and RSS Agregator application. I'm just using...
9
by: Julia Briggs | last post by:
How do I construct a <iframe> or equivalent for FireFox/NS browsers, inside a screen centered <div> tag? Can it be done?
3
by: BrianB830 | last post by:
Hello all, I have a quick question regarding an MS Access database I'm creating. In the entity "ORDER", I have the attributes "Order Date" and "Delivery Date". I need to create a validation...
1
by: Jim | last post by:
Hello... I have just completed chapters 1-9 of Jessie's Learning C#. Great tutorial! But, talk about method overloading, I'm overloaded with OOPs! Can someone offer me some advise, please? I...
1
by: B. Cavour | last post by:
How do you link a form's help button to a specific topic in the generated help? thanks, BC
1
by: elsa | last post by:
My instructer has given me a backward question to answer!! how can we describe the process of normalization that led to this table to 4NF? wardName ------ staffName---- ...
6
by: =?Utf-8?B?Q2hyaXMgRA==?= | last post by:
Hi - can someone PLEASE tell me what's wrong with the script below. In debug I verified that 'registrant' has a value. I can't figure our how to build the URL & this script generates the error...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.