|
Hey guys,
I made a small change and the code seems to be working properly now. The revision I made is that in the user-defined method, checkPalindrome, I changed the first conditional statement to if(start == end). So instead of
if(stringIn.length() - 1 == 0 && start == end)
The code now reads
if( start == end)
I'll try some more combinations and if I find an error, I'll post back.
|
|
|
|
|
Does Code Project have ongoing projects which one can participate in like a spectator or also join the coding team?
Is it possible to download project source code from a project on code project.
Priety.
|
|
|
|
|
prietycool wrote: Is it possible to download project source code from a project on code project.
Yes, see these articles[^].
|
|
|
|
|
Hi,
I want to participate in a java web project which uses springs and hibernate.
So that I can learn to configure and use springs and hibernate in a web project.
Is this possible on code project?
Priety.
|
|
|
|
|
|
We have to use different sorting algorithms to sort an array. So I already got the quick, bubble, and insertion sort working and I am not posting the code since it already works However the Merge Sort is giving me problems. I already searched online but could not find the right answer. Anyway...here it goes. We were provided with some code snippets and have to make them work. What data do they want when they say min, max? I thought that it would be the first element in the array and the last....No? cause its not working like that. Here is my code please someone help me what they want...
import java.io.*;
import java.util.*;
class MergeSortArray
{
public static void main(String[] args)
{
int choice = 0;
int[]values;
int counter = 0;
int backCounter = 10;
values = new int[10];
while(counter != 10)
{
Scanner scanner = new Scanner (System.in);
System.out.println("Enter " + backCounter + " more integers:");
choice = scanner.nextInt();
values[counter] = choice;
counter++;
backCounter--;
}
System.out.println(counter);
mergeSort (values, 0, values.length-1);
merge (values, first, mid, last);
int i=0;
while(i<10)
{
System.out.println(values[i]);
i++;
}
}
public static void mergeSort (Comparable[] data, int min, int max)
{
if (min < max)
{
int mid = (min + max) / 2;
mergeSort(data, min, mid);
mergeSort(data, mid+1, max);
merge (data, min, mid, max);
}
}
public static void merge (Comparable[] data, int first, int mid, int last)
{
Comparable[] temp = new Comparable[data.length];
int first1 = first, last1 = mid;
int first2 = mid + 1, last2 = last;
int index = first1;
while (first1 <= last1 && first2 <= last2)
{
if (data[first1].compareTo(data[first2]) < 0)
{
temp[index] = data[first1];
first1++;
}
else
{
temp[index] = data[first2];
first2++;
}
index++;
}
while (first1 <= last1)
{
temp[index] = data[first1];
first1++;
index++;
}
while (first2 <= last2)
{
temp[index] = data[first2];
first2++;
index++;
}
for (index = first; index <= last; index++)
data[index] = temp[index];
}
}
Please help me to get this working. Pretty Please!!!
|
|
|
|
|
1. Did you revise what your teacher said about merge sort.
2. Min is the smallest value in the array and Max is the biggest value in the array.
I did not check your code but here is a nice working example:
http://www.cs.colorado.edu/~main/applications/Mergesort.java[^]
In line 42 modify it to mergesort(data, 0, data.length);
Good luck
|
|
|
|
|
Member 4277480 wrote: In line 42 modify it to mergesort(data, 0, data.length);
Thanks for the answer. But from what I can see this is pretty much what I have.
mergeSort (values, 0, values.length-1);
Here is the error message I am getting maybe this will help
MergeSortArray.java:30: mergeSort(java.lang.Comparable[],int,int) in MergeSortArray cannot be applied to (int[],int,int)
|
|
|
|
|
Doh got it fixed had to change comparable [] to int[] ...silly mistake.
|
|
|
|
|
By the way the line I told you to change was from the link I told you about not yours
Any way good to hear you got it to work.
Regards
|
|
|
|
|
Member 4277480 wrote: By the way the line I told you to change was from the link I told you about not yours
Yeah I figured this out after starring at it for a bit!
But now I have another issue. I commented it with a bunch of ***** where the error is.
import java.io.*;
import java.util.*;
class MergeSortArray
{
public static void main(String[] args)
{
int choice = 0;
int[]values;
int counter = 0;
int backCounter = 10;
values = new int[10];
while(counter != 10)
{
Scanner scanner = new Scanner (System.in);
System.out.println("Enter " + backCounter + " more integers:");
choice = scanner.nextInt();
values[counter] = choice;
counter++;
backCounter--;
}
System.out.println(counter);
mergeSort (values, 1, values.length-1);
int i=0;
while(i<10)
{
System.out.println(values[i]);
i++;
}
}
public static void mergeSort (int[] data, int min, int max)
{
if (min < max)
{
int mid = (min + max) / 2;
mergeSort(data, min, mid);
mergeSort(data, mid+1, max);
merge (data, min, mid, max);
}
}
public static void merge (int[] data, int first, int mid, int last)
{
int[] temp = new int[data.length];
int first1 = first, last1 = mid;
int first2 = mid + 1, last2 = last;
int index = first1;
while (first1 <= last1 && first2 <= last2)
{
if (data[first1].compareTo(data[first2]) < 0)
{
temp[index] = data[first1];
first1++;
}
else
{
temp[index] = data[first2];
first2++;
}
index++;
}
while (first1 <= last1)
{
temp[index] = data[first1];
first1++;
index++;
}
while (first2 <= last2)
{
temp[index] = data[first2];
first2++;
index++;
}
for (index = first; index <= last; index++)
data[index] = temp[index];
}
}
I get the error MergeSortArray.java:72: int cannot be dereferenced
I tried changing:
if (data[first1].compareTo(data[first2]) < 0)
to
;if (data[first1]== data[first2] < 0)
But that did not work either. Any idea how I would code this right?
|
|
|
|
|
import java.io.*;
import java.util.*;
class MergeSortArray
{
public static void main(String[] args)
{
int choice = 0;
Comparable[] values;
int counter = 0;
int backCounter = 10;
values = new Comparable[10];
while (counter != 10)
{
Scanner scanner = new Scanner(System.in);
System.out.println("Enter " + backCounter + " more integers:");
choice = scanner.nextInt();
values[counter] = choice;
counter++;
backCounter--;
}
mergeSort(values, 0, values.length - 1);
System.out.println();
int i = 0;
while (i < 10)
{
System.out.print(values[i] + " ");
i++;
}
}
public static void mergeSort(Comparable[] data, int min, int max)
{
if (min < max)
{
int mid = (min + max) / 2;
mergeSort(data, min, mid);
mergeSort(data, mid + 1, max);
merge(data, min, mid, max);
}
}
public static void merge(Comparable[] data, int first, int mid, int last)
{
Comparable[] temp = new Comparable[data.length];
int first1 = first, last1 = mid;
int first2 = mid + 1, last2 = last;
int index = first1;
while (first1 <= last1 && first2 <= last2)
{
if (data[first1].compareTo(data[first2]) < 0)
{
temp[index] = data[first1];
first1++;
}
else
{
temp[index] = data[first2];
first2++;
}
index++;
}
while (first1 <= last1)
{
temp[index] = data[first1];
first1++;
index++;
}
while (first2 <= last2)
{
temp[index] = data[first2];
first2++;
index++;
}
for (index = first; index <= last; index++)
data[index] = temp[index];
}
}
Well you had some mistakes but all is well now.
|
|
|
|
|
Thanks so much. I was so close. It all works now. I appreciate it.
~Silke~
|
|
|
|
|
Hi all,
I have the following function call that returns a string value after encryption or decryption. My problem is how to write this string value to a text file.
String outStr= RunRC4(InputFile,aKey);
try {
BufferedWriter out = new BufferedWriter(new FileWriter(args[2], true));
out.write(outStr + "\n");
out.close();
} catch (Exception e) {
System.err.println(e.getMessage());
}
public static String RunRC4(String InputFile,String aKey)
Can anyone help?
Thanks in advance!!!
|
|
|
|
|
import java.io.*;
public class FileWrite
{
public static void main(String[] args) throws Exception
{
PrintWriter out = new PrintWriter(new File("test.text"));
out.print("The String Value");
out.close();
}
}
Good luck
|
|
|
|
|
how to move cookie value from https to http page? In my project, login page is in https.and page of after login is in http.here the i cant get cookie value.Is there any solution?Please help me.
modified on Friday, September 18, 2009 4:16 AM
|
|
|
|
|
Wrong forum. Try asking in web development.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Using Cookies That Are Transmitted by Both HTTP and HTTPS
Because HTTP and HTTPS requests are sent to different ports, some browsers may not include the cookie sent in an HTTP request with a subsequent HTTPS request (or vice-versa). This may cause new sessions to be created when servlet requests alternate between HTTP and HTTPS. To ensure that all cookies set by a specific domain are sent to the server every time a request in a session is made, set the cookie-domain element to the name of the domain. The cookie-domain element is a subelement of the session-descriptor element in the WebLogic-specific deployment descriptor weblogic.xml. For example:
<session-descriptor>
<cookie-domain>mydomain.com</cookie-domain>
</session-descriptor>
The cookie-domain element instructs the browser to include the proper cookie(s) for all requests to hosts in the domain specified by mydomain.com. For more information about this property or configuring session cookies, see Setting Up Session Management.[^]
from http://download.oracle.com/docs/cd/E13222_01/wls/docs90/webapp/progservlet.html[^]
Good Luck
|
|
|
|
|
Thank u.I am using apache tomcat server.here what will i do?
|
|
|
|
|
Hi all !
I want use FreeTTS for my application. I can use the code bellow to read the Hello World in English.
How can i read another language for example German or French,...
My code here :
package com.myprj.demo;
import java.io.File;
import java.io.PrintStream;
import java.util.Locale;
import javax.speech.Central;
import javax.speech.EngineList;
import javax.speech.synthesis.*;
public class HelloWorld
{
public HelloWorld()
{
}
private static String noSynthesizerMessage()
{
String message = "No synthesizer created. This may be the result of any\nnumber of problems. It's typically due to a missing\n\"speech.properties\" file that should be at either of\nthese locations: \n\n";
message = message + "user.home : " + System.getProperty("user.home") + "\n";
message = message + "java.home/lib: " + System.getProperty("java.home") + File.separator + "lib\n\n" + "Another cause of this problem might be corrupt or missing\n" + "voice jar files in the freetts lib directory. This problem\n" + "also sometimes arises when the freetts.jar file is corrupt\n" + "or missing. Sorry about that. Please check for these\n" + "various conditions and then try again.\n";
return message;
}
public static void main(String args[])
{
String voiceName = args.length <= 0 ? "kevin16" : args[0];
System.out.println();
System.out.println("Using voice: " + voiceName);
try
{
SynthesizerModeDesc desc = new SynthesizerModeDesc(null, "general", Locale.GERMAN, null, null);
Synthesizer synthesizer = Central.createSynthesizer(desc);
if(synthesizer == null)
{
System.err.println(noSynthesizerMessage());
System.exit(1);
}
synthesizer.allocate();
synthesizer.resume();
desc = (SynthesizerModeDesc)synthesizer.getEngineModeDesc();
Voice voices[] = desc.getVoices();
Voice voice = null;
int i = 0;
do
{
if(i >= voices.length)
break;
if(voices[i].getName().equals(voiceName))
{
voice = voices[i];
break;
}
i++;
} while(true);
if(voice == null)
{
System.err.println("Synthesizer does not have a voice named " + voiceName + ".");
System.exit(1);
}
synthesizer.getSynthesizerProperties().setVoice(voice);
synthesizer.speakPlainText("Hello world", null);
synthesizer.waitEngineState(0x10000L);
synthesizer.deallocate();
System.exit(0);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
1.So if i want to the program read the "Datum" String in German my code must be change to :
<br />
SynthesizerModeDesc desc = new SynthesizerModeDesc(null, "general", Locale.GERMAN, null, null);<br />
<br />
synthesizer.speakPlainText("Datum", null);<br />
Is it ok or another ways?
2.How many languages FreeTTS support ? which are they?
Best regards !
|
|
|
|
|
English is the main language supported and if you want to add another this is what the website mentions:
How do I add support for a language other than English?
This is not a trivial task as it requires a lexicon for the language as well as various statistical data about the language. The document http://festvox.org/festvox/festvox_toc.html describes this is more detail.
from: http://freetts.sourceforge.net/docs/index.php#How_do_I_add_support_for_a_voice_with[^]
Regards
|
|
|
|
|
I have a code I've been working on in JCreator for school and i can't seem to get it right. Will somebody please help me with this and tell me what I am doing wrong?
/* Author: Dale Leach
* Date: 9/15/09
* File: Goods Hands Program
* Desc: To find out if an auto is insurable.
*/
import java.io.*;
public class goodHands
{
// declare global scope variables
private BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
private String inputString;
public goodHands()throws IOException //I-O-P
{
initialize();
insureProcess();
cleanUp();
}//end constuctor
public void initialize()
{
System.out.println();
System.out.println("Welcome to the Goods Hands Program.");
System.out.println();
}// end initialize
public void insureProcess() throws IOException
// declare local variable for car choice
{
String carChoice;
boolean insurable = false;
int carYear;
boolean year = false;
System.out.println ("Please enter a car model: ");
inputString = input.readLine();
carChoice = inputString;
// Check Model for insurability
insurable = checkModel(carChoice);
// Check Year for insurability
System.out.println("Please enter year of car: ");
carYear = Integer.parseInt (input.readLine());
year = checkYear (carYear);
printResults(year);
// Print results based on insurability
}// end insureProcess
public boolean checkModel(String carChoice)
{ boolean insurable = false;
if (carChoice==("Ford") carChoice==("Chevy") carChoice.==("Toyota"))
insurable = true;
return insurable;
}// end checkModel
public boolean checkYear(int year)
{
boolean year = false;
if(carYear = 1990) year = true;
return year;
}// end checkYear
public void printResults(boolean insurable)
{
if (insurable);
System.out.println("Car is insurable.");
else
System.out.println("Sorry your car is not insurable.");
}// end printResults
public void cleanup()
{
System.out.println();
System.out.println("The Good Hands Program is complete.");
System.out.println("Have a nice day.");
}// end cleanup
public static void main(String [] args) throws IOException // main method
{
new goodHands();
} // end the main method
} // end the program
|
|
|
|
|
Use either Eclipse or Netbeans the latter IDEs show you exactly where your errors are:
1. The constructor of a class has the same name as the class (Line 17).
2. In line 61 you have a typo error in your third equality plus what are you doing with your equalities i.e. what are you using in between them is it an and or an or....
3. In line 69 the same variable cant have many data type.
4. In line 71 the variable your using in the method is hidden from that method so define in it outside the method as either public,protected,private and since your using it in a static method also static.
5. In line 81 to 83 you have a typo error. In line 81 remove the semi colon from the if statement.
Good luck
|
|
|
|
|
My advice would be to ask your teacher. Most teachers won't mind if you ask a sensible question, they don't think it's stupid, they think it shows interest in the subject and they should be happy to help. After all, they are there to teach you (in theory at least).
From a quick glance at the code you have posted above, this line does not look right:
if (carChoice==("Ford") carChoice==("Chevy") carChoice.==("Toyota"))
Neither does this line:
if (insurable);
I probably wouldn't do all the work in the constructor, either. If I say much more than that, I'll be doing your homework for you, which I am not going to do.
|
|
|
|
|
Looking for reading Material on Concurrent Programming in Java. Im trying to understand Pthreads and semaphore
|
|
|
|
|