Separate Input And Output In Console In Eclipse - eclipse

I am using Eclipse to run my java programs but there is a problem with Eclipse's console that the input and output appears in the same console. For example
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int t = scan.nextInt();
while(t-- > 0) {
int n = scan.nextInt();
System.out.println(n);
}
scan.close();
}
For this code let the input be
2
3
4
then the output that i gets looks like
2
3
43
4
Is there any way to get separate input and output and get the distinction in eclipse.

One could re-assign System.in and/or System.out as discussed here.
Of course, this is not Eclipse-specific solution but a Java one.
I would be working with files in first place.

Related

I get the same error on multiple systems and programs

This is the program I'm trying to run. I have tried on two different systems and I get the exact same error message on both. I get the error message whenever I enter a price with a decimal e.g 4.2.
Code for the program:
package grocerylist;
import java.util.Scanner;
public class GroceryList {
public static void main(String[] args) {
float [] prices = new float [5];
Scanner in = new Scanner (System.in);
System.out.println("Enter 5 prices: ");
prices[0] = in.nextFloat();
prices[1] = in.nextFloat();
prices[2] = in.nextFloat();
prices[3] = in.nextFloat();
prices[4] = in.nextFloat();
float total = prices[0] + prices[1] + prices[2] + prices[3] + prices[4];
System.out.println("The total of the 5 items are: "+total);
}
}
The error message is on line 12 and goes like this:
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:864)
at java.util.Scanner.next(Scanner.java:1485)
at java.util.Scanner.nextFloat(Scanner.java:2345)
at grocerylist.GroceryList.main(GroceryList.java:21)
C:\Users[username]\AppData\Local\NetBeans\Cache\8.2\executor-snippets\debug.xml:83: Java returned: 1
The solution was simpler than what I first imagined. #DualCoreMax had the right mindset for the solution. Which was, when the user is typing in prices the user needs to use the comma sign to diffrenciate between the integer number and decimal number.
I seriously thought I had a way more major problem on my hands here, glad is is just a matter of my own stupidity. Thank you to everyone who came to help me, a first year student.

Why is my Sphinx4 Recognition poor?

I am learning how to use Sphinx4 using the Maven plug-in for Eclipse.
I took the transcribe demo found on GitHub and altered it to process a file of my own. The audio file is 16bit, mono, 16khz. It is approximately 13 seconds long. I noticed that it sounds like it is in slow motion.
The words spoken in the file are, "also make sure it's easy for you to access the recording files so you could upload it if asked".
I am attempting to transcribe the file and my results are horrendous. My attempts at finding forum posts or links that thoroughly explain how to improve the results, or what I am not doing correctly have lead me no where.
I am looking to strengthen the accuracy of the transcription, but would like to avoid having to train a model myself due to the variance in the type of data that my current project will have to deal with. Is this not possible, and is the code I am using off?
CODE
(NOTE: Audio file available at https://instaud.io/8qv)
public class App {
public static void main(String[] args) throws Exception {
System.out.println("Loading models...");
Configuration configuration = new Configuration();
// Load model from the jar
configuration
.setAcousticModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us");
// You can also load model from folder
// configuration.setAcousticModelPath("file:en-us");
configuration
.setDictionaryPath("resource:/edu/cmu/sphinx/models/en-us/cmudict-en-us.dict");
configuration
.setLanguageModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us.lm.dmp");
StreamSpeechRecognizer recognizer = new StreamSpeechRecognizer(
configuration);
FileInputStream stream = new FileInputStream(new File("/home/tmscanlan/workspace/example/vocaroo_test_revised.wav"));
// stream.skip(44); I commented this out due to the short length of my file
// Simple recognition with generic model
recognizer.startRecognition(stream);
SpeechResult result;
while ((result = recognizer.getResult()) != null) {
// I added the following print statements to get more information
System.out.println("\ngetWords() before loop: " + result.getWords());
System.out.format("Hypothesis: %s\n", result.getHypothesis());
System.out.print("\nThe getResult(): " + result.getResult()
+ "\nThe getLattice(): " + result.getLattice());
System.out.println("List of recognized words and their times:");
for (WordResult r : result.getWords()) {
System.out.println(r);
}
System.out.println("Best 3 hypothesis:");
for (String s : result.getNbest(3))
System.out.println(s);
}
recognizer.stopRecognition();
// Live adaptation to speaker with speaker profiles
stream = new FileInputStream(new File("/home/tmscanlan/workspace/example/warren_test_smaller.wav"));
// stream.skip(44); I commented this out due to the short length of my file
// Stats class is used to collect speaker-specific data
Stats stats = recognizer.createStats(1);
recognizer.startRecognition(stream);
while ((result = recognizer.getResult()) != null) {
stats.collect(result);
}
recognizer.stopRecognition();
// Transform represents the speech profile
Transform transform = stats.createTransform();
recognizer.setTransform(transform);
// Decode again with updated transform
stream = new FileInputStream(new File("/home/tmscanlan/workspace/example/warren_test_smaller.wav"));
// stream.skip(44); I commented this out due to the short length of my file
recognizer.startRecognition(stream);
while ((result = recognizer.getResult()) != null) {
System.out.format("Hypothesis: %s\n", result.getHypothesis());
}
recognizer.stopRecognition();
System.out.println("...Printing is done..");
}
}
Here is the output (a photo album I took): http://imgur.com/a/Ou9oH
As Nikolay says, the audio sounds odd, probably because you haven't resampled it in the right way.
To downsample the audio from the original 22050 Hz to the desired 16kHz, you can run the following command:
sox Vocaroo.wav -r 16000 Vocaroo16.wav
The Vocaroo16.wav will sounds much better and it will (probably) give you better ASR results.

Sequence of Project Deployment in Mule

Does anybody know in what sequence, the mule project are loaded when the Mule starts-up?
It doesn't seem to be in alphabetical order or last updated time.
If you look at the class MuleDeploymentService, you can see the following:
String appString = (String) options.get("app");
if (appString == null)
{
String[] explodedApps = appsDir.list(DirectoryFileFilter.DIRECTORY);
String[] packagedApps = appsDir.list(ZIP_APPS_FILTER);
deployPackedApps(packagedApps);
deployExplodedApps(explodedApps);
}
else
{
String[] apps = appString.split(":");
Description for method File.list states that "there is no guarantee that the name strings in the resulting array will appear in any specific order". So, I guess the answer is in no particular order, or in the order they are listed in using the -app option.

Source not found error while performing data driven testing in selenium using java in eclipse

Hi,
public static String[][] excelRead() throws Exception{
FileInputStream fis=null;
HSSFWorkbook wb=null;
File excel=new File("C:\\MyEclipseWorkspace\\SeleniumWD\\Commodity1.xlsx");
fis=new FileInputStream(excel);
wb=new HSSFWorkbook(fis);
HSSFSheet ws=wb.getSheet("com");
int rowCount=ws.getLastRowNum()+1;
int colCount=ws.getRow(0).getLastCellNum();
String[][] data=new String[rowCount][colCount];
for(int i=0;i<rowCount;i++){
HSSFRow row=ws.getRow(i);
for(int j=0;j<colCount;j++){
HSSFCell cell=row.getCell(j);
String value= cellToString(cell);
data[i][j]=value;
System.out.println("Value is " +value);
}
}
return data;
}
I am working with selenium Eclipse and have to perform data driven testing. I wrote a code below to import an excel sheet data.
The below methods does so,
Now since i am executing this method it shows Source not found. I am not able to find the solution to this. I have already include poi-3.9.jar file in the library.
Please assists me regarding this.
Thanks in advance,

How to hide console window of subprocess?

I'm trying to write a very simple program to replace an existing executable. It should munge its arguments slightly and exec the original program with the new arguments. It's supposed to be invoked automatically and silently by a third-party library.
It runs fine, but it pops up a console window to show the output of the invoked program. I need that console window to not be there. I do not care about the program's output.
My original attempt was set up as a console application, so I thought I could fix this by writing a new Windows GUI app that did the same thing. But it still pops up the console. I assume that the original command is marked as a console application, and so Windows automatically gives it a console window to run in. I also tried replacing my original call to _exec() with a call to system(), just in case. No help.
Does anyone know how I can make this console window go away?
Here's my code:
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
char* lpCmdLine,
int nCmdShow)
{
char *argString, *executable;
// argString and executable are retrieved here
std::vector< std::string > newArgs;
// newArgs gets set up with the intended arguments here
char const ** newArgsP = new char const*[newArgs.size() + 1];
for (unsigned int i = 0; i < newArgs.size(); ++i)
{
newArgsP[i] = newArgs[i].c_str();
}
newArgsP[newArgs.size()] = NULL;
int rv = _execv(executable, newArgsP);
if (rv)
{
return -1;
}
}
Use the CreateProcess function instead of execve. For the dwCreationFlags paramter pass the CREATE_NO_WINDOW flag. You will also need to pass the command line as a string as well.
e.g.
STARTUPINFO startInfo = {0};
PROCESS_INFORMATION procInfo;
TCHAR cmdline[] = _T("\"path\\to\\app.exe\" \"arg1\" \"arg2\"");
startInfo.cb = sizeof(startInfo);
if(CreateProcess(_T("path\\to\\app.exe"), cmdline, NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &startInfo, &procInfo))
{
CloseHandle(procInfo.hProcess);
CloseHandle(procInfo.hThread);
}
Aha, I think I found the answer on MSDN, at least if I'm prepared to use .NET. (I don't think I'm really supposed to, but I'll ignore that for now.)
System::String^ command = gcnew System::String(executable);
System::Diagnostics::Process^ myProcess = gcnew Process;
myProcess->StartInfor->FileName = command;
myProcess->StartInfo->UseShellExecute = false; //1
myProcess->StartInfo->CreateNowindow = true; //2
myProcess->Start();
It's those two lines marked //1 and //2 that are important. Both need to be present.
I really don't understand what's going on here, but it seems to work.
You need to create a non-console application (i.e. a Windows GUI app). If all this app does is some processing of files or whatever, you won't need to have a WinMain, register any windows or have a message loop - just write your code as for a console app. Of course, you won't be able to use printf et al. And when you come to execute it, use the exec() family of functions, not system().