|
Greetings all.
I have a program calculation ip address like this.
public static void main(String[]args){
int host=450;
String sMask="255.255.254.0";
String[] octet;
String IpAddress="192.168.100.0";
octet = IpAddress.split("\\.");
int oct1=Integer.parseInt(octet[0]);
int oct2=Integer.parseInt(octet[1]);
int oct3=Integer.parseInt(octet[2]);
int oct4=Integer.parseInt(octet[3]);
int i;
System.out.println("Ip Address \t \tSubnet Mask");
for(i=oct4;i<host;i++){
System.out.println(oct1+"."+oct2+"."+oct3+"."+i+"\t \t"+sMask);
}
}
print out from this program
Ip Address Subnet Mask
192.168.100.0 255.255.254
192.168.100.1 255.255.254
192.168.100.2 255.255.254
192.168.100.3 255.255.254
until...
192.168.100.449 255.255.254
I want this program,if ip address octet 4 value "192.168.100.255",then continuing this program,like this.
next >
192.168.101.0 255.255.254
192.168.101.1 255.255.254
192.168.101.2 255.255.254
until ...
192.168.101.193 and Finish.
What the lack from my program?
|
|
|
|
|
You need to add some extra code to cater for when i gets above 255. Something like:
for(i=oct4;i<host;i++){
int value = i / 256;
int rem = i % 256;
oct3 += value;
System.out.println(oct1 + "." + oct2 + "." + oct3 + "." + rem + "\t \t" + sMask);
}
Use the best guess
|
|
|
|
|
The code above increments both oct3 and oct4 at the same time, one ahead the other, respectively.
Change:
oct3 += value; to:
oct3 = value; for:
for(i=oct4;i<host;i++){
int value = i / 256;
int rem = i % 256;
oct3 = value;
System.out.println(oct1 + "." + oct2 + "." + oct3 + "." + rem + "\t \t" + sMask);
}
|
|
|
|
|
Actually we were both wrong; it should be:
value += oct3;
System.out.println(oct1 + "." + oct2 + "." + value + "." + rem + "\t \t" + sMask);
Use the best guess
|
|
|
|
|
good call.
|
|
|
|
|
Hi,
We have a requirement to capture a signature on the tablet in 3 byte ASCII format and then base64 encoding on it. Maximum characters allowed is 1024 only.The requirement is for browser based thin client
Thanks
|
|
|
|
|
when i run my web project with tomcat(stat as a NT service),if the service start with system users ,the project won't run properly,
however,when the service log on with administrator(current user),the project run successfully.why ?
|
|
|
|
|
Because the local system account has different permissions and environment than the user.
There are many possible reasons why it might fail.
And if you check your resources before using and log errors it would probably tell you exactly what those are.
|
|
|
|
|
I have checked the tomcat log, and the problem has been solved .
thank you~ ^-^
|
|
|
|
|
Hi!! I'm trying to understand the sharpen your pencil Class Puzzle4 from head first java.. But the math and the logic is confusing me... I hope someone can give me some explanation before I move on in the book... The output of the code should be Result 543345
public class Puzzle4 {
public static void main (String[] args){
Puzzle4b[] obs = new Puzzle4b[6];
int y = 1;
int x = 0;
int result = 0;
while (x < 6){
obs[x] = new Puzzle4b();
obs[x].ivar = y;
System.out.println("obs[x] = " + obs[x].ivar);
y = y * 10;
System.out.println(" Y = " + y);
x = x + 1;
System.out.println(" x = " + x);
}
x = 6;
System.out.println(" x = " + x);
while (x > 0){
x = x - 1;
System.out.println(" x = " + x);
System.out.println("obs[x].doStuff(x) = " + obs[x].doStuff(x));
result = result + obs[x].doStuff(x);
}
System.out.println("Result " + result);
}
}
class Puzzle4b {
int ivar;
public int doStuff(int factor){
if (ivar > 100){
System.out.println("ivar = " + ivar);
return ivar * factor;
}
else{
return ivar * ( 5 - factor );
}
}
}
What isreturn ivar * ( 5 - factor );????
ivar is an instance and the value of it is unique to every object is that right?? The logic of the method is confusing me. I understand that x is the argument to
modified 15-Jul-13 17:27pm.
|
|
|
|
|
ivar is an integer variable whose value is set for every new instance of the Puzzle4b class. However, without a lot more information it's anyone's guess what its purpose is or what this project is about. I suggest you go back to wherever you found this code and ask the person who wrote it.
Use the best guess
|
|
|
|
|
obs[5]= 100000>100 true. 100000*5= 500000
obs[4]= 10000 >100 True. 10000*4= 40000
obs[3]= 1000 > 100 true. 1000*3= 3000
obs[2]= 100>100 False. 100*(5-2)= 300
obs[1]= 10>100 False. 10*(5-1)= 40
obs[0]= 1>100 False. 1*5= 5
Add them all up you get 543345
|
|
|
|
|
Fascinating! And what is that supposed to mean?
Use the best guess
|
|
|
|
|
Did you really read the code dude?
The output is 543345 observe that the object obs[x] is an array that means obs[x]= {1,10,100,1000,10000,100000}
obs[5]= 100000>100 true. 100000*5= 500000
obs[4]= 10000 >100 True. 10000*4= 40000
obs[3]= 1000 > 100 true. 1000*3= 3000
obs[2]= 100>100 False. 100*(5-2)= 300
obs[1]= 10>100 False. 10*(5-1)= 40
obs[0]= 1>100 False. 1*5= 5
add them and you will get the 543345.. I understand the logic now how come you still don't and you were trying to help me?
|
|
|
|
|
|
Skykitten,
First of all, you would do well in life not to antagonize someone whom is trying to help you. Not cool.
Second, you act like the code was so easy for someone out-of-context to understand and you can't get the jist of it? If it is so simple why are you here asking what it is?
Let's take a look at your code:
while (x < 6){
obs[x] = new Puzzle4b();
obs[x].ivar = y;
System.out.println("obs[x] = " + obs[x].ivar);
y = y * 10;
System.out.println(" Y = " + y);
x = x + 1;
System.out.println(" x = " + x);
}
This particular part initializes 6 instances of the Puzzle4b class and assigns them to parts of an array(obs[x]). with each increment(loop), y(which is used to initialize the ivar integer here) is incremented by multiples of 10. so for each instance created: 1, 10, 100, 1000...etc. this ivar is for the calculation done here:
public int doStuff(int factor){
if (ivar > 100){
System.out.println("ivar = " + ivar);
return ivar * factor;
}
else{
return ivar * ( 5 - factor );
}
when this method is called(horrible name by the way, dostuff? really?) it is called upon each instance, which causes the calculations to be unique to each instance. ie obs[1]'s ivar = 10, so 10 is used when I call the dostuff method on that particular instance. so on and so forth. The factor variable is nothing more than the name assigned to the variable passed to the method so that it can do the calculation and send it back to your main thread for printing.
at this point, since you were being a bit brash, i digress. Figure the rest out by RTFM.
Good day.
|
|
|
|
|
I don't think this reply was meant for me.
Use the best guess
|
|
|
|
|
You are correct. it was for skytten.
|
|
|
|
|
When Installling application on a clients machine which of the Connection string will work?
1.
String conUrl = "jdbc:sqlserver://localhost:1433; databaseName=paytest; user=sa; password=; integratedSecurity=true;";
2.
String conUrl = "jdbc:sqlserver://localhost:1433; databaseName=paytest; user=mypc; password=; integratedSecurity=true;";
|
|
|
|
|
Depends whether your client has a SQL server running at port 1433, his firewall doesn't play games with your app and quietly allows the connection and the username and password is valid.
So, the bottom line:
Unable to predict.
Good Luck!
Beauty cannot be defined by abscissas and ordinates; neither are circles and ellipses created by their geometrical formulas.
Source
|
|
|
|
|
What happens when you try it?
Use the best guess
|
|
|
|
|
Is this a general question or a specific one?
In general neither will work.
Typically a customer that uses SQL Server will have a SQL Server box. And your app won't run on that box. So localhost won't work.
The port is often the default but that can vary by SQL Server version as either 1433 or 1434.
The point of 'integratedSecurity' is specifically so the user/pwd is NOT in the connection string so it seems pretty pointless in the present form.
A company that has a SQL Server installation is unlikely to use your user\pwd but would rather insist on using their own so hard coding the url in code will not work.
|
|
|
|
|
It is just meant for 3-4 PC (Small application),so if I use SQL Express 2008 on the clients machine(other than on testing machine) so the username and password is the same ,we will configure the port accordingly ,so this will work?
|
|
|
|
|
I have a I have homework about "synchronization'.
This is my demo :
NumberX.java
import java.io.Serializable;
public class NumberX implements Serializable{
int myNumber;
public NumberX() {}
public NumberX(int myNumber) {this.myNumber = myNumber;}
public int getMyNumber() {return myNumber;}
public void setMyNumber(int myNumber) { this.myNumber = myNumber;}
public void newNumber(){myNumber = myNumber +10;}
}
ProcessServlet.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
int x = Integer.parseInt(request.getParameter("txtNumber"));
NumberX n = new NumberX(x);
n.newNumber();
System.out.println(n.getMyNumber());
request.setAttribute("number", n.getMyNumber());
request.getRequestDispatcher("index.jsp").forward(request, response);
}catch(Exception e){
e.printStackTrace();
}
finally {
out.close();
}
}
index.jsp
<body>
<h1>My Test </h1>
<%
if(request.getAttribute("number")!=null){
int i= (Integer)request.getAttribute("number");
%>
<h1 style="color:red"><%=i%></h1>
<% } %>
<form action="ProcessServlet" method="POST">
<input type="text" name="txtNumber"/>
<input type="submit" value="+"/>
</form>
</body>
My prolem is when I open this demo in 2 browser as 2 users .
How to synchronize 'myNumber' when :
User1 -> input(5) + clicks -> 15
User2 -> Will see 15 (<-- not refesh page )
and Otherwise .
Can anyone help me ,pls ?
|
|
|
|
|
I guess you want something like user hit count of any web site. If yes then you have think about the init() of the servlet . Because its only executed when the servlet is called for the first time.So if you define a variable inside this block , and increment that value in processRequest() , you will get the hit count.
Regards
Shubhashish
|
|
|
|