How To End Reading From Console

May 21, 2014

This is my program. All is working fine except stopping reading from console. Problem is that even after you write done if you are fast enough you are able to write more. As you can see I can't close scanner because of two inputs. Even so I tried to close it but problem was still here.

public static void main(String...args) {
System.out.println("Write first input:");
System.out.print(streamToString(System.in, ""));
System.out.println("Write secondinput:");
System.out.print(streamToString(System.in, ""));

[Code] .....

View Replies


ADVERTISEMENT

Reading From Text File - Print Linked List On Console

Mar 9, 2015

How can i convert this linked list code to a read from input.txt

The first line in the input file will give the elements to initialize the linked list with. Consecutive lines will provide operation instructions.

Your code should read one line at a time. After reading each line, it should perform the corresponding operation and print the linked-list on the console.

If an operation is not possible, it should print "N/A".

Sample input file. Please note, the comments (// ...) are given for explanation, the input file will not have them:

4, 5, 6, 3// First line. This will provide the initial values for the linked list : 4->5->6->3
1, 9// Add a 9 at the front of the linked-list. After this operation the linked-list should be: 9->4->5->6->3
2, 1// Add a 1 at the end of the linked-list. After this operation the linked-list should be: 9->4->5->6->3->1
3, // Delete the first node in the linked-list. After this operation the linked-list should be: 4->5->6->3->1
4, // Delete the last node in the linked-list. After this operation the linked-list should be: 4->5->6->3
5, 11// Delete the node with the value 11 in it. Since this is not possible, it should print "N/A"
5, 6// Delete the node with the value 6 in it. After this operation the linked-list should be: 4->5->3

Sample output to the console:

4->5->6->3
9->4->5->6->3
9->4->5->6->3->1
4->5->6->3->1
4->5->6->3
N/A
4->5->3

My Code:

LinkedList.Java

class linkedList
{
protected Node start;
protected Node end ;
public int size ;
 
[Code] .....

View Replies View Related

Console Says Terminated When Try To Run

Feb 13, 2015

Trying to run my program after getting rid of code errors (I think) and now it doesn't produce anything but <terminated> in the console window. The produce is suppose to analyse text from a file and produce the percentage of words used

package com.project;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.math.BigDecimal;

[Code] ....

erfrf.jpg

View Replies View Related

How To Clear Console Screen

Apr 2, 2014

How to clear console screen ? I am using Linux machine.

1) Runtime.getRuntime().exec("clear"); // this is not working. Not clearing the screen

2) for ( int i = 0; i < SOME_NUMBER; i++)
System.out.println();

2nd way is working but i think it is not a good option as i need to move scroll bar again and again.

View Replies View Related

TXT File Into CSV Output On Console?

Feb 12, 2015

i need to take a txt file and turn it into a csv(comma seperated value) output on console but where to begin.

View Replies View Related

Centered Alignment For Console

Feb 8, 2015

"Write a java application that displays the following patterns separately one below the other.

Use for loops to generate the patterns. There are 4 Triangle patterns.

All asterisks (*) should be printed by a single statement of the form System.out.print('*');

This is 4-different patterns, not 1-pattern."

The first 2 triangles are right angles and is simple to make with a loop with in a loop

The 3rd triangle is like an inverted christmas tree and the 4th one is a christmas tree. ( It's not showing properly on the board so i deleted it). I can't seem to make the 3rd and 4th triangle line up properly it looks like this (the _ represents blank spaces on the console)

_____*_____

_____**_____

____***_____

____****_____

___*****____

___******_____

__*******

__********____

Notice how the sides of the triangle isn't straight and the triangle looks like its dancing, the assignment requires it to be a straight line. is there anyway to do this? This is suppose to be the output. all the lines of the triangle is straight and not jagged ...

public class myclass {
public static void main(String[] args) {
int counter = 1;
int counter2 = 1;
while (counter != 11){
EmptyLine();

[Code] .....

My code for those particular triangle is in the work because I cant figure out how to make it look like that.

View Replies View Related

How To Input Data From Console

Nov 7, 2014

I want to input character data from the console without using the BufferedReader class. I tried using the Scanner class but the compiler shows an error. This is what I tried:

sc.nextCharacter();
sc.nextcharacter();
sc.nextChar();
Sc.nextchar();

Is there any way I can input character data without using the BufferedReader class?

View Replies View Related

Losing Control Of The Console

Jun 14, 2014

I have a multithreaded java program. I have a few worker threads which process data over a udp server. Then I have another thread for console input. The problem is when there is an error with one of the worker threads, and it prints to the console, my console thread loses "focus", that is, the while loop seems to no longer run. Here is the console thread:

Java Code:

public void run() {
Console c = System.console();
if (c == null) {
Logger.writeError("No console.");
System.exit(1);
}
while(true){
String login = c.readLine(">>>: ");
System.out.println("You entered: " + login);
}
} mh_sh_highlight_all('java');

When an exception is raised, it prints it to the console, and suddenly the program no longer shows the >>> prompt from above.

View Replies View Related

Java Console SQL DB Query App

Nov 4, 2014

I seem to be having a issue with my java console app what it should do is query a SQL DB and list the user details (userid, firstname ,lastname) from the user table, and the users stocks (stockname ,stockdiscription) associated to each user from the userstocks table if I'm thinking correctly!

I'm sure it is just a logical error, but I'm not sure of the way to get the out put I'm looking for. I will add the makeDB.java file and DatabaseQuery.java file as well as the current Exception(Run Time Exception) below.

**I have added other users and stocks manually - Not just what the MakeDB.java file inserts **

Output and Exception:

Stock holdings by User
User ID User Name
Stock - Description
-------------------------------------------
admin01 Default Admin
Exception in thread "main" java.sql.SQLException: ResultSet is closed
at sun.jdbc.odbc.JdbcOdbcResultSet.checkOpen(JdbcOdbcResultSet.java:6647
)
at sun.jdbc.odbc.JdbcOdbcResultSet.next(JdbcOdbcResultSet.java:1248)
at DatabaseQuery.main(DatabaseQuery.java:45)
Press any key to continue . . .

Java Code:

MakeDB.java:
import java.sql.*;
import java.io.*;
public class MakeDB
{
public static void main(String[]args) throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

[Code] ....

View Replies View Related

ProcessBulider Output To Console

Mar 10, 2014

I have written a shell script which connects to oracle database and performs operation and returns some output message. Script works fine from command prompt. My requirement is to make it run from a web page which I have accomplished. I am getting the output of shell script on a different web page defined by HTML form action in my jsp file. Everything is working fine.

Below is the part of java class I have written:

=============
String fileName = "build_"+ request.getParameter("region");
String arg1 = request.getParameter("release");
String arg2 = request.getParameter("email");
ProcessBuilder pb = new ProcessBuilder(fileName,arg1,arg2);
Process p = pb.start();
InputStream inputStream = p.getInputStream();

[Code] ....

As shown above, my shell script accepts 2 arguements . User enters arguements in the fields provided which are passed to shell script by processbuilder. Script runs successfully and displays output [ success/error ].

But my problem is , the shell script takes nearly 1 hour to do its job in the database and untill then my web page keeps showing as busy. Whereas in command prompt, shell script displays messages as it runs and thus keeps the end user informed about its progress. However, when called from java it waits untill the shell script completes/terminates and finally displays all the messages at once. I want to know if there is a way to display the shell script output on web page as it continues to run in the background ( child process ).

I tried without the waitFor() function but no luck. It still waits for shell script to exit before displaying any message.

View Replies View Related

Writing To Console With PrintWriter

May 1, 2015

I thought you can use PrintWriter to write to the console but when I run the following code I only get "abc" printed to the console.

import java.io.*;
class Class1{
public static void main(String...abc) throws Exception{
PrintWriter writer = new PrintWriter(System.out);
writer.println("test");
System.out.println("abc");
}
}

View Replies View Related

Outputting Calendar On Console

Oct 14, 2014

I created a calendar program so when the user enters a day number and a year it would show the calendar for the year . My issue was that I could not get the numbers to line up neatly and how they should look . Also if its not to much trouble I would like to know how to turn this in to a loop .

import java.util.Scanner;
public class Calendar {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter a Year");
int Year = scanner.nextInt();

[Code] .....

View Replies View Related

Console Input Of Strings Using Scanner

May 9, 2015

I am having a great deal of frustration trying to use the scanner to get user input from the eclipse console. Here is what I am trying to do.

Print a menu for the user with options, take that (1) char input and run it into a switch statement for processing. I have that done and it is working fine.

If the user chooses to enter strings for storage, They are instructed to enter their string and press enter to complete that string entry. Then enter the next string and press enter, etc.

So I have a While loop for this. Get the scanner input, store it in the LinkedList, get the next scanner input, etc. I get the scanner string and store it in a Linked list. That works fine. The user is instructed to simply enter a blank string to end the entry procedure, like just press Enter on the new line without typing a new string.

The problem is the scanner doesn't seem to return anything for me to Test to close this procedure. How do I TRAP the fact that the user just pressed enter so I can end my procedure? I have tried next() and nextLine() and reset(), etc. And I am getting knowhere.

View Replies View Related

Clear Console In Eclipse And Goto

May 26, 2014

Follow the //? FIRST and SECOND notes, then I understood that Java has GOTO as Keyword for future versions and that usually one can avoid GOTO using break inside the cycles, but I need a jump( salto) in the code.

import java.util.Scanner;
public class ArrayOrdinati {
public static void main (String[] args){
int[] Array = {5,3,1};
int e=Array.length;
int b;

[Code] .....

View Replies View Related

Writing A Large Symbol In The Console

Sep 3, 2014

What I'm tasked to do, is to make a simple Java class that forms a "V" based on whatever height the user would desire, made out of stars "*", and spaces " ".

For example, if a user desires a "V" with a height of 3, it would look print out something like;

* *
* *
*

Where a "V" with a height of 5 would look something like:

* *
* *
* *
* *
*

(That one didn't look too good, but you get the point, it's suppose to be 5 "high" and shaped like a "V"). The problem I have, is that I don't see what loops within loops within loops I would need to build something like this.

All the easy stuff like asking the user what height they want and such, I can handle, but I don't see how this thing is suppose to be coded, to print out a decent-looking and right-sized "V" in the console.

public static void main(String[] args) {
int height = 3;
for (int i = 0; i < height; i++) {
for (int j = 0; j < 2/(height+1)+1; j++) {
if(j == i) {

[Code] ....

Looked like something of a good start, and it drew me half (!) of the "V" in the size I wanted. Am I on to it here, or am I on the moon in terms of progress? I need the entire "V", not just a nice "".

View Replies View Related

Console Based Interface Loop

Mar 11, 2015

I am implementing a console based interface for an assigment. I've got a DAO interaces and implementations ready and I am stuck on a loop that checks whether to display logged in menu or logged out menu.

public static void main(String[] args) throws SQLException {
Main consoleInterface = new Main();
boolean runningLoop = consoleInterface.isRunning();
boolean loggedOutLoop, loggedInLoop;
while(runningLoop) {

[Code] ....

So when this runs it should show loggedIn() method only and only if the condition is not met. At the start when program runs I set loggedOutLoop = true and loggedInLoop = false. When I handle login I set loggedOut = false and loggedIn = true

What seems to happen is that the else statement doesnt work and the output I've got is only loggedOut() method displayed where I only want loggedIn() to be displayed without loggedOut().

View Replies View Related

Input From Console To Array List?

Dec 10, 2014

I have this very simple application just to test console input:

import java.util.ArrayList;
import java.util.Scanner;
public class WriteTester {

[Code]....

When I let it run, only every third entry is put into the array list and I have to hit "enter" three times for the "break" in line 21 to trigger. I cannot find out why.

View Replies View Related

How To Clear Java Output Console

May 2, 2014

how to clear my java output console?

View Replies View Related

How To Change Background Color Of Console

Mar 30, 2014

I'm using eclipse to run my java program.

I want to be able to change the background color of the console when the user types in a particular command..

e.g User types: color blue

Then the background color of the console should turn blue

Is this possible and how would I go about doing it?

View Replies View Related

Console Freezes When Working In Different Threads

Jul 22, 2014

I have a console application. One thread allows a user to directly input into a console. Another thread listens on a tcp port, takes input, processes it, and then writes it to the console. The work in different threads, but in tcp thread, one I call a method outside that thread that writes to console, it often gets stuck. here is a mockup of situation:

Java Code:

import java.io.BufferedReader;
import java.io.Console;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

[Code] ......

It often freezes on "Attempt 1". Before I used System.out there, I also tried console.writer() there but both freeze at that point often. Any situation where console or System.out.writeln freeze when working across threads and why it is occurring? It almost feels like one thread has locked the console so the others can't write to it.

View Replies View Related

Formatting Tables For Console Output?

Apr 13, 2014

I am writing a class which formats console output as a table. It displays the type of an entry, the name of an entry, and the data for an entry. I am stuck on a required for loop which appends a tab character to a string, for formatting it as a table. It doesn't seem to be adding any of the tabs and I can't tell what I've done wrong. As far as I can tell the contents of the loop are never reached, and I can't make sense of it.

The ConsoleWriter class that contains the code that is in error...

Java Code:

package frontend;
public class ConsoleWriter {
private static String tabbedData(String data, int min) {
System.out.println(); //for debug
int tabcount = 0;
int len=8*min;

[code]....

View Replies View Related

Google Speech API Not Found On Console

May 20, 2014

i want to know about to convert speech to text in java..,

i found some articles are released to achieve this target (Speech 2 text) by using the Google Speech API from Google console.

i have already account & using the Map & other API too. But i unable to found the Google Speech API now..,

Sample Link : Speech to Text Library for Processing (STT)

what shall i do to achieve my target..

View Replies View Related

Limit On String Input From Console

Mar 2, 2015

I am trying to make a program in which first I am entering number of charachters and then in nextline their is exactly that number of characters should be enter after than program should stop taking input from console..this is I have try so far

private static ArrayList<String> chars;
static String inputdata;
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
chars=new ArrayList<String>();

[code]....

View Replies View Related

How To Create Jar Library With Console Command

Apr 22, 2015

How to do create jar library with console system Windows .?

View Replies View Related

Game Class - Nothing Will Print Into Console

May 7, 2014

I'm new to java, and i'm trying to make a gaming, but for some reason nothing will print into the console. I want it to have the system to print out the frames, and ticks, but nothing will happen.

package ca.trey.game; 
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Dimension;
import javax.swing.JFrame;
public class Game extends Canvas implements Runnable {
 
[Code] .....

View Replies View Related

Text Output In Console In BOLD

Aug 2, 2014

package midtermproject;
import java.util.Scanner; //Using for scanner class
import java.awt.Font; //Using for bold
public class MidtermProject {
/**
* @param args the command line arguments
*/
public static void main(String[] args, String setBoldText) {

[code]....

I need the console to display BOLD for the movie title only. I imported java.awt but I do not know what else or how else to do it. I have looked in my book, online, youtube, yahoo answers and I want to figure this out. I found an answer on here that someone talked about java.awt but did not specific what.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved