|
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
|
|
|
|
|
Can u send me some links about that ?
|
|
|
|
|
|
|
Hi there .. Im new to Cloud computing but I have developed much apps in C#. I want to develop a SaaS application in Java, plz tell me what I need to learn in java except its basics which I have learnt. Should I call SaaS a web application? do i have to learn JavaScript to develop SaaS ?. Plz any one that can guide me or give me a list "What I have to Do"
SamHash
|
|
|
|
|
This is really a Google question[^], rather than a Java question.
Use the best guess
|
|
|
|
|
Sir , I want to ask that is there essential to use a PaaS or IaaS provided by google, amazon and Microsoft? I just learned that there is a software -- or whatever that is called specifically -- named "CloudSim" Which can be used to create your own cloud on a server by using cloud architecture and by a VM. I dont know how to use them, and is this is good to have your own cloud than using others infrastructure ?
|
|
|
|
|
Sorry, but I have no idea, this forum is for Java programming questions. Maybe you would get a better answer to your query in the Cloud Computing[^] or Quick Answers[^] forums.
Use the best guess
|
|
|
|
|
Hi, I am new to java and am working on a sales tax project. And I can't seem to even get the project tested as it is. Can anyone help me please?
The full error message I get is
java.lang.NullPointerExpection at SaleBad.total(SaleBad.java:42)
and the code line it highlights is in the method below:
public double total()
{
double sum = 0;
for (SalesLine s: saleLines) {
sum = sum + s.price();
}
if (state.equals( "AL")) sum = sum * 1.07;else
if (state.equals( "AK")) sum = sum * 1.04; else
Thank you!
|
|
|
|
|
|
Same question happened before to me. refer the following link. u ll find the answer Null point exception[^]
|
|
|
|
|
Im goin to a online bank assignment in java using DAO technigues with mysql.it is not printing an error or exception.but it always jumps to false part.here my code, please tell where I go wrong and how to fix it..
Login.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<title>Insert title here
Login
UserName:
Password:
<%=request.getAttribute("loginMsg") %>
UserServlet.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
String operation = request.getParameter("operation");
if(operation!=null && operation.equalsIgnoreCase("login")){
loginDetail(request,response);
}else if(operation!=null && operation.equalsIgnoreCase("login")){
logout(request,response);
}
}
private void loginDetail(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
User u = new User();
UserService us =new UserServiceImpl() ;
String Uname = request.getParameter("txtUname");
String Pwrd = request.getParameter("txtPwrd");
u.setUname(Uname);
u.setPwrd(Pwrd);
System.out.println(Uname+""+Pwrd);
try {
if(us.Userlogin(u.getUname(),u.getPwrd())){
String message = "Thank you, " + Uname +"..You are now logged into the system";
HttpSession session = request.getSession(true);
session.setAttribute("username", Uname);
session.setAttribute("password", Pwrd);
response.setContentType("text/html");
request.setAttribute("message", message);
request.getRequestDispatcher("/Menu.jsp").forward(request, response);
}else {
String message = "You have to register first or check Your user name password again!";
request.setAttribute("loginMsg", message);
RequestDispatcher rd = getServletContext().getRequestDispatcher("/Login.jsp");
rd.forward(request, response);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
UserServiceImpl.java
@Override
public boolean Userlogin(String Uname, String Pwrd) {
// TODO Auto-generated method stub
boolean result=false;
UserDAO udoi = new UserDAOImpl();
User user = new User();
System.out.println("ppp");
user.setUname(Uname);
user.setPwrd(Pwrd);
System.out.println("//////");
System.out.println(user.getUname()+user.getPwrd());
if(user!=null){
System.out.println(user.getUname()+user.getPwrd());
result = udoi.getLoginDetail(Uname, Pwrd);
//result=true;
}
return result;
}
UserDAOImpl.java
@Override
public boolean getLoginDetail(String Uname, String Pwrd) {
// TODO Auto-generated method stub
System.out.println(Uname+"++"+Pwrd);
Connection conn=null;
ResultSet rs=null;
boolean SUCCESS=false;
try {
conn=getConnection();
//String sql="SELECT * FROM login WHERE UserName='amal' and password='secret' ";
String sql="SELECT * FROM login WHERE UserName='" + Uname + "' and Password='"+ Pwrd + "' ";
System.out.println(sql);
Statement stmt=conn.createStatement();
rs = stmt.executeQuery(sql);
System.out.println("ddddddddddddddddd" + rs==null);
System.out.println("sssssssssssssssss" + rs.next());
while(rs.next()) {
System.out.println(Uname+"*_*"+Pwrd);
String uname=rs.getString("UserName");
String password=rs.getString("Password");
System.out.println(Uname+"***"+Pwrd);
if ((uname.equals(Uname)) && (password.equals(Pwrd))){
SUCCESS=true;
}else {
SUCCESS=false;
}
}
}
catch (Exception e){
e.printStackTrace();
}finally {
try {
conn.close();
rs.close();
} catch (SQLException ex) {
Logger.getLogger(AccountDAOImpl.class.getName()).log(Level.SEVERE, null, ex);
}
}
return SUCCESS;
}
private Connection getConnection() {
// TODO Auto-generated method stub
ConnectionFactory cf = new ConnectionFactory();
Connection conn = null;
try {
conn = cf.getConnection();
} catch (SQLException ex) {
Logger.getLogger(AccountDAOImpl.class.getName()).log(Level.SEVERE, null, ex);
}
return conn;
}
EveryImpl file has it's interfaceclass.please tell me where I go wrong. Thank you!
|
|
|
|
|
Cross post.
Regards
Shubhashish
|
|
|
|
|
Im goin to a online bank assignment in java using DAO technigues with mysql.it is not printing an error or exception.but it always jumps to false part.here my code, please tell where I go wrong and how to fix it..
Login.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form name="input" action="login" method="post">
<h1>Login</h1><br>
UserName: <input type="text" name="txtUname"><br>
Password: <input type="password" name="txtPwrd"><br>
<input type="submit" value="Login" onclick= <a href="main/Servelet"</a> >
<input type="hidden" name="operation" value="login">
<p><%=request.getAttribute("loginMsg") %></p>
</form>
</body>
</html>
UserServlet.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String operation = request.getParameter("operation");
if(operation!=null && operation.equalsIgnoreCase("login")){
loginDetail(request,response);
}else if(operation!=null && operation.equalsIgnoreCase("login")){
logout(request,response);
}
}
private void loginDetail(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
User u = new User();
UserService us =new UserServiceImpl() ;
String Uname = request.getParameter("txtUname");
String Pwrd = request.getParameter("txtPwrd");
u.setUname(Uname);
u.setPwrd(Pwrd);
System.out.println(Uname+""+Pwrd);
try {
if(us.Userlogin(u.getUname(),u.getPwrd())){
String message = "Thank you, " + Uname +"..You are now logged into the system";
HttpSession session = request.getSession(true);
session.setAttribute("username", Uname);
session.setAttribute("password", Pwrd);
response.setContentType("text/html");
request.setAttribute("message", message);
request.getRequestDispatcher("/Menu.jsp").forward(request, response);
}else {
String message = "You have to register first or check Your user name password again!";
request.setAttribute("loginMsg", message);
RequestDispatcher rd = getServletContext().getRequestDispatcher("/Login.jsp");
rd.forward(request, response);
}
} catch (Exception e) {
e.printStackTrace();
}
}
UserServiceImpl.java
@Override
public boolean Userlogin(String Uname, String Pwrd) {
boolean result=false;
UserDAO udoi = new UserDAOImpl();
User user = new User();
System.out.println("ppp");
user.setUname(Uname);
user.setPwrd(Pwrd);
System.out.println("//////");
System.out.println(user.getUname()+user.getPwrd());
if(user!=null){
System.out.println(user.getUname()+user.getPwrd());
result = udoi.getLoginDetail(Uname, Pwrd);
}
return result;
}
UserDAOImpl.java
@Override
public boolean getLoginDetail(String Uname, String Pwrd) {
System.out.println(Uname+"++"+Pwrd);
Connection conn=null;
ResultSet rs=null;
boolean SUCCESS=false;
try {
conn=getConnection();
String sql="SELECT * FROM login WHERE UserName='" + Uname + "' and Password='"+ Pwrd + "' ";
System.out.println(sql);
Statement stmt=conn.createStatement();
rs = stmt.executeQuery(sql);
System.out.println("ddddddddddddddddd" + rs==null);
System.out.println("sssssssssssssssss" + rs.next());
while(rs.next()) {
System.out.println(Uname+"*_*"+Pwrd);
String uname=rs.getString("UserName");
String password=rs.getString("Password");
System.out.println(Uname+"***"+Pwrd);
if ((uname.equals(Uname)) && (password.equals(Pwrd))){
SUCCESS=true;
}else {
SUCCESS=false;
}
}
}
catch (Exception e){
e.printStackTrace();
}finally {
try {
conn.close();
rs.close();
} catch (SQLException ex) {
Logger.getLogger(AccountDAOImpl.class.getName()).log(Level.SEVERE, null, ex);
}
}
return SUCCESS;
}
private Connection getConnection() {
ConnectionFactory cf = new ConnectionFactory();
Connection conn = null;
try {
conn = cf.getConnection();
} catch (SQLException ex) {
Logger.getLogger(AccountDAOImpl.class.getName()).log(Level.SEVERE, null, ex);
}
return conn;
}
EveryImpl file has it's interfaceclass.please tell me where I go wrong. Thank you!
|
|
|
|
|