|
Renu Meena wrote: I already searched but which one is perfect
If it runs on my computer I can always reverse engineer it.
If you want to protect your intellectual property then create a service not a product.
|
|
|
|
|
Yeah. you are right but i am bind to provide product only because it is hardware related issue
|
|
|
|
|
Hi I wrote a method for determining whether an integer is a palindrome like below. and for the input number -2147483648 I get true as it's output but in reality the output should be false. It seems the Collections.reverse(list) in my method doesn't work, I mean it doesn't reverse the input. I appreciate if someone can help my problem.
<pre> public boolean isPalindrome(int x) {
String raw=String.valueOf(x);
if(raw.charAt(0)=='-')
raw=raw.substring(1);
List<Character> list = new ArrayList<Character>();
for(char c:raw.toCharArray())
list.add(c);
List temp=list;
Collections.reverse(list);
return temp.equals(list);
}
modified 12-Mar-18 16:29pm.
|
|
|
|
|
ElenaRez wrote: my method doesn't work. Please explain exactly what that means.
|
|
|
|
|
I mean if you test the program with the input number -2147483648 the result according to my method implementation will be true while in reality as you see the mentioned number is not palindrome and the result should be false. I can't understand what is the problem in my code.
|
|
|
|
|
The problem is the following line in your code:
List temp = list;
which does not create a copy of the original, but just a new reference. So when list gets sorted, temp also points to the sorted elements.
To create a copy of the original you should replace the above line with the following:
List temp = new ArrayList<Character>();
temp.addAll(list);
|
|
|
|
|
Thank you so much for your great answer.
|
|
|
|
|
Hello. I have written a code like below for Valid Parentheses problem. and after running it, I get error such: Exception in thread "main" java.lang.OutOfMemoryError: Java heap space in the line where I push in the stack. Could any one help what is the problem?
class Solution {
public boolean isValid(String s) {
Stack<Character> stack = new Stack<Character>();
int i=0;
boolean result=false;
if(s.length()==0||s==null) return true;
while(i<s.length()){
if(s.charAt(i)=='('||s.charAt(i)=='{'||s.charAt(i)=='[')
stack.push(s.charAt(i));
if((!stack.empty())&&(s.charAt(i)==')'||s.charAt(i)=='}'||s.charAt(i)==']')){
if(stack.peek()==s.charAt(i)){
stack.pop();
i++;
continue;
}
else
result=false;
}
}
if(stack.empty())
return true;
return result;
}
}
|
|
|
|
|
I would guess that the two following if statements are not correct, so you are stuck in the while loop.
if((!stack.empty())&&(s.charAt(i)==')'||s.charAt(i)=='}'||s.charAt(i)==']')){
if(stack.peek()==s.charAt(i)){
So if you have just encountered an open bracket the first of these statements will be false, because i is still pointing to the open bracket in your string. The loop will just continue round examining the same character.
|
|
|
|
|
Hi,
1. what Richard said.
2. Your code is far from correct, there is no reason whatsoever to look more than once at the same character, so index i should get incremented unconditionally, hence a for-loop or better yet a foreach-loop would be preferable.
3. You shouldn't be calling CharAt() over and over, do it once and store the result in currentCharacter
4. What closes a "{" isn't another "{", it is a "}"; an easy way to get this, is by having separate test-and-push combinations (if it is "{" then push "}").
|
|
|
|
|
Elenora wrote: stack.push(s.charAt(i));
Only way that code can run out of memory is if that line is called way to many times.
|
|
|
|
|
i made a form that select file and provide key i want to encrypt that file by aes encrytion in jsp
my form code is:=
<html>
<body bgcolor="#006699" text=#006699 >
<center>
<br>
<div style="width:95%;border-style:solid;border-width:3px;border-color:white;height:600px;border-radius:15px;background-color:white;box-shadow:-1px -1px 20px black" >
<img src=../images/titlebar.jpg width=100% style="border-radius:15px" >
<h1>Encrypt Document</h1>
<hr color=orange size=3px>
<form name=f1 method=post action=uploadfile.jsp enctype="multipart/form-data" >
<input type=hidden name=demo value=demo >
<table>
<tr><td>Select File</td><td><input type=file name=filename required size=60 ></td></tr>
<tr><td>Enter Key</td><td><input type=text name=title size=80 required ></td></tr>
<tr><td></td><td><input type=submit name=btnencript value=Encrypt onclick=dosubmit() ></td></tr>
</table>
<hr color=orange size=3px>
</form>
</div>
</center>
</body>
</html>
|
|
|
|
|
|
Hey there,
I´m going to code breakout in java via the mvc pattern. And I have some problems with it.
Here´s my approach so far:
Model: coordinates of bricks, ball, panel and given coordinates by mouseListener
Controller: every physics, what happens with collisions, how to move the ball
View: every object that has to be drawn
But I´m not really cool with that because I´m not really confident about the implementation. And how do I put everything together to let the game run?
Grateful for any advice!
|
|
|
|
|
|
Posting a single word is not a question.
At least your repost of this in QA[^] provided some details of the question.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Does make for a fast read though.
|
|
|
|
|
Hi i am a beginner user of Java and I want to make an weather Java program which use gui and the openweathermap api. Can anyone help me???
|
|
|
|
|
|
1. Learn how to write a problem
2. Learn about sockets. Probably need to learn about http and Rest also (but I didn't look at the API.)
3. Learn about UI
4. Create a program that uses the weather API. This uses 1, 2
5. Create a program that displays the results. This uses 1, 2, 3, 4.
|
|
|
|
|
You want to write a desktop or web application?
|
|
|
|
|
Hello,
I am learning hoe to program in Java and have come up with some code to practice what I have learned. I have created a program to enter password and confirm it and the only way I have found to do this is to exit the program and try it again. Please help
Scanner scanner3 = new Scanner(System.in);
String passwordConfirm = scanner3.nextLine();
if (passwordConfirm.equals(password) ) {
System.out.println("Your password has been confirmed");
}
else {
System.out.println("The passwords do not match, please try again below");
Scanner scanner5 = new Scanner(System.in);
String passConfirm = scanner5.nextLine();
if (passConfirm.equals(password) ) {
System.out.println("The passwords now match, thank you");
scanner5.close();
}
else {
System.out.println("The passwords still do not match, please reload the app to try again");
System.exit(0);
}
}
Your help is greatly appreciated! I have the same problem with confirming email but once I figure out password, I can do email myself.
|
|
|
|
|
A do-while loop is perffect for that:
String passwordConfirm;
do {
System.out.println("Please enter password:");
passwordConfirm = scanner3.nextLine();
} while (!passwordConfirm.equals(password));
System.out.println("Your password has been confirmed");
will keep asking for password until the correct one is provided.
If you want only a fixed number of tries, you may have to declare a counter variable, increased in the loop, and tested in the while statement.
"I'm neither for nor against, on the contrary." John Middle
|
|
|
|
|
Hi there,
Thanks for the help. But could I ask where I place that code and the code I should replace with it? I can't seem to figure out where to put it and the code to erase. Thanks!
|
|
|
|
|
It could replace the whole code block you have shown, except the first line which declares the scanner3 variable.
"I'm neither for nor against, on the contrary." John Middle
|
|
|
|