|
Waaaaaaaaay too much code. The least you could do is format it as a <code> block.
|
|
|
|
|
the (inputString == reverseString) if-conditional always returns false (even if it is true. please help. Couldn't figure this out. thanks.
import java.util.Scanner;
public class ReverseString{
public static void main (String[] args){
String inputString="";
int inputStringLength;
String reverseString="";
String stringHolder="";
Scanner in = new Scanner(System.in);
System.out.print("Enter a String: ");
inputString = in.next();
inputStringLength = inputString.length();
System.out.println("Input String is : " +inputString);
for (int i = 0; i<inputStringLength; i++){
stringHolder = inputString.charAt(i) + stringHolder;
reverseString = stringHolder;
}
System.out.println(reverseString);
System.out.println("inputString = " + inputString);
System.out.println("input length =" + inputString.length() + "reverse length " +reverseString.length());
System.out.println("Now let's test to see if your input is a palindrome (like hannah or 'a man, a plan, a canal, panama') \n" + "Does "+ inputString +" = the same forward and reversed? \n^^^ \n^^^ " );
if (inputString == reverseString){
System.out.println("yes!");
System.out.println(" YES!! Eureka! " + inputString + " == " + reverseString + "! Thus, " + inputString + " is a palindrome! gratzee!");
}else {
System.out.println("no");
System.out.println("NO!! \n" + inputString + " != (does not equal) " + reverseString + "\n So " + inputString + "is not a palindrome! Oh well no prob!" );
}
}
}
I've tried using scaffolding code to test for what is going on. I think someway reverseString is created may be a problem. But when I print reverseString and inputString they both have the same string length and visibly the same characters...so I don't know what the solution is at present.
|
|
|
|
|
You should be using String.equals() [^].
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Hey really? Thanks Richard MacCutchan! Thanks for taking the time to look at that code, too. It's not yet solved b/c I have to try that comparison method, but thanks!!
However, I thought it was something like that so made a mini test program.
String var1 = "hello";
String var2 = "hello";
if (var1==var2){
System.out.println("equal!");
}
and THAT did show they were equal. If the String.equals() method works (and gets my ReverseString.java program to work, why would that above var1==var2 work but not so with inputString and reverseString?
Thanks!!
|
|
|
|
|
Well if you had read a bit more detail from the page I pointed you to you would understand that the above expression works only because var1 and var2 refer to the same String object, not because the strings themselves match. And from that it follows that you must always use String.equals() to get an actual comparison of the characters within the strings.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
oh bloody hell. was so excited to see a response, didn't even notice that you linked something.
I researched and found
"The == operator will only be true if two String references point to the same underlying String object. Hence two Strings representing the same content will be equal when tested by the equals(Object) method, but will only by equal when tested with the == operator if they are actually the same object."
which I "sorta" understand. like same object in memory referenced and two diff objects but with same string value (== only works as true with the former)
so == seems to compare objects in memory and String.equals() actually compares Strings (content of String objects).
Sweet am finally getting this a bit!!
Thanks for such complete answer...and now that that obstacle is resolved, my coding can progress for the day!
(Also I tried it and now that mini-app totally works. Thanks again!)
This is site is so much better than stackoverflow haha.
|
|
|
|
|
johtnkucz wrote: This is site is so much better than stackoverflow haha.
If nothing else you get a 5 for that comment.
Seriously, thanks for the feedback, it's always welcome, and good luck with your project(s).
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
I never rely on luck. I prefer efficiency and preparation (and utilizing awesome resources like this site!)!! Seriously thanks for the positive feedback...on my positive feedback!!
Seriously though This is my number one code-help (I have other resources for tutorials and stuff but if get stuck and need help) this owns other sites, including stack overflow. Your response was extremely helpful. thanks again so much for looking at code.
And re stackoverflow. I hate that site. Most comments and posts have this gross disgusting milieu of (ooh look how much coding I know or some cheesy leet rubbish of "no, you're supposed to post this way..or that way.." or whatever.
I just was thoroughly stumped, chucked up some code:
1. got the EXACT answer that was the prob
2. learned somethign I never fully understood even after a wretched computer science class and most all autodidactic(== compares objects not content of objects and strings may be equal but diff objects, so if linked to diff objects same content will appear as not equal because their objects are not equal but their content is) .
That's the epitome of helpful. Anyways if one gets similar exchanges, this is num 1 code resource. good times. The layout of forum posts/responses is unique and novel but appealing, too. Good tiems.
Were you involved in making this site or something, or just prefer this (anti overflow) to other sites, too. Cheers. thanks.
|
|
|
|
|
johtnkucz wrote: Were you involved in making this site or something
No, I'm just one of the 8.5 million ...
If you want to know a bit more about the site see here[^], and if you want to know who are the great people who did make the site then look here[^].
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Buy using stringBuffer and string equals method we can check try this following code
import java.util.Scanner;
import java.lang.*;
public class ReverseString{
public static void main (String[] args){
String inputString="";
int inputStringLength;
String reverseString="";
String stringHolder="";
Scanner in = new Scanner(System.in);
System.out.print("Enter a String: ");
inputString = in.next();
StringBuffer sb=new StringBuffer(inputString);
sb=sb.reverse();
if(inputString.equals(sb.toString()))
{
System.out.println("palindrome");
}
else
{
System.out.println("Not palindrome");
}
}
}
|
|
|
|
|
I have created a java servlet in which i have fetch the value from database using mysql i just want to use this fetch value in to my Js file.
So how can i do this????
Reply
swapnil
|
|
|
|
|
|
I display the progress bar for downloading attachments and it works fine … but when I am downloading some attachments I get the exception message:
Exception in thread "main" com.sun.mail.util.DecodingException: BASE64Decoder: Error in encoded stream: needed 4 valid base64 characters but only got 1 before EOF, the 10 most recent characters were: "Q3w5ilxj2P"
I found the explanation:
Certain IMAP servers do not implement the IMAP Partial FETCH functionality properly. This problem typically manifests as corrupt email attachments when downloading large messages from the IMAP server. To workaround this server bug, set the "mail.imap.partialfetch" property to false. You'll have to set this property in the Properties object that you provide to your Session.
http://java.sun.com/products/javamail/NOTES113.txt
So I turned off partial fetch:
Properties props = System.getProperties();
props.setProperty("mail.store.protocol", "imaps");
props.setProperty("mail.imaps.partialfetch", "false");
Session session = Session.getDefaultInstance(props, null);
Store store = session.getStore("imaps");
store.connect("imap.gmail.com", "<username>","<password>");
this solved the problem ….however the method getInputStream() from the Part class blocks the thread until the attachment is completely downloaded and it is impossible to get the information about the number of bytes which have been already downloaded from mailbox. Without this information it is impossible to display the progress bar. So is there a way to obtain this information and display the progress bar?
|
|
|
|
|
Firstly, put the download on a separate thread so that you don't hang.
Secondly, can you get the size of the attachment?
You can always use a guestimate of how long is left, and then tick your progress accordingly.
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|
|
"Secondly, can you get the size of the attachment?"
Yes.
"You can always use a guestimate of how long is left, and then tick your progress accordingly."
This is good idea. Many progress bars are based on some estimations.
|
|
|
|
|
Where and how do you get that size? You need to have that before the attachment is received.
I have a similar request here and have declined it so far. Would be great to get some input from a different angle.
The estimation and some fake value to show to the user is complicated to manage.
|
|
|
|
|
I know the size beforehand because my program works with the mailboxes which ALWAYS have only 1 MB size attachments.
|
|
|
|
|
Hi All,
Does anybody know of any good tutorials for java and WIA integration? I am looking to create a java application that will integrate with a WIA compatible scanner and am just looking for a good place to start.
Many thanks,
Graeme
|
|
|
|
|
graeme.m wrote: looking for a good place to start.
You found it[^].
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Thanks Richard, but i have already searched that. Links provided are mainly products already developed or apis that have a large liscence fee behind them.
(Only posting here as I have exhausted my google searching abilities)
|
|
|
|
|
You said you were looking for a good place to start, and Google is it. If there are no reasonable tutorials or user guides in the list then chances are that they have not been published; although I did notice that the first link includes full documentation. Whether these products are free or not is, of course, another issue.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Thanks Richard, I should have been more specific in my original post. After being unable to find any useful information through google for free apis, I can use JTwain etc if needs be, I thought I would post here to see if anybody has been down this road before and could provide me with useful information on getting started.
|
|
|
|
|
|
Hi Gerbi,
This is one of the sites I came accross. It provides a very good introduction to using java with scanners though the only downfall is that the solution uses JTwain (highest liscence fee i have seen) though if i cannot find any opensource APIs this may be the way I will go. I may also start looking into a C# implementation.
Much thanks for your reply
|
|
|
|
|
Dont be confused by JTwain name used in this demo, it has not relation to asprise products.
When you have installed twain sdk you can build demo mentioned on this article.
It is not complete api/product but it is good point to start from.
|
|
|
|