Changing Output - Each Row Printed Out On Single Line
Jan 19, 2014
I have the following code....................
double[][] cmMatrix = eval.confusionMatrix();
for(int row_i=0;row_i<cmMatrix.length; row_i++){
for(int col_i=0;col_i<cmMatrix.length;col_i++){
myConsole.getOut().println(cmMatrix[row_i][col_i]);
myConsole.getOut().println("|");
}
myConsole.getOut().println();
}
What do I need so that each row is printed out on a single line ?
View Replies
ADVERTISEMENT
Jul 21, 2014
If I code:
int num0=0,num1=1,num999=999;
System.out print(num0+","+num1);
System.out println(","+num999);
I believe I'll get: 0,1,999 but I want 0000,0001,0999 i.e. a width of 4 for small integers.
View Replies
View Related
Nov 12, 2014
I am aware that the default value of char is 0. But in this program I am getting some unexpected output
public class TestClass12{
static int[] ia = new int[1];
static char ch;
public static void main(String args[]) throws Exception{
System.out.println("ch:"+ch+" ia[ch]:"+ia[ch]);
}
}
Output:
ch: ia[ch]:0
If you see the above output ch is printed as a blank space instead of 0, while the array default value is correctly printed by taking the char default value as index. Why is ch printed as blank space?
View Replies
View Related
Oct 6, 2014
Write a program to request a student number and their marks in 4 subjects. The program must print the student number, total marks and average mark. All outputs should be printed with suitable labels
This is the error am getting
Scanner get = new Scanner (System.in) - got a red line
int student number, total marks, average mark - got a yellow bulb with a red exclamation mark on it.
I just dont understand where the errors is where what the system dont have ... I am using netbeans ....
View Replies
View Related
Oct 12, 2014
I have to read data from a text file and print it in a new text file. An example of one line is like this:
Johnson 85 98 75 89 82
I then have to take the average of all the numbers and assign a "grade" to the numbers for each line of the text file and make a new file so it looks like this for 10 lines:
Name 1 2 3 4 5 Average Grade
Johnson 85 98 75 89 82 85.80 B
My problem is extracting the data from the file so I can use it.
View Replies
View Related
Dec 20, 2014
I want to take input in the following way:
Sample Input 1
3
45 3 14
Sample Input 2
5
12 34 5 56 7
The first line is the number of test cases and the second line is the corresponding values for the test cases. Java code for taking multiple inputs in the single line separated by a space.
View Replies
View Related
Jul 17, 2014
I am using Java 1.6, I have this class ....
import java.util.ArrayList;
import java.util.List;
public class TestDrive
{
public TestDrive()
{
super();
[Code] ....
What is the most efficient way to group the preferences of the same type, In other word I want just a print statement to print this line.
BREAKFAST(Eggs,Milk),SPORTS(Basket,Tennis),....
View Replies
View Related
Dec 12, 2014
I am checking how to do following task.
01. pickup the selected text file and read the line by line and output the text in to visual text pane.
what i did:.
01. I wrote code that read the text file and output in to jave console/ also some of the interface.
the code read txt file:
Java Code:
String fileName = "C:/Users/lakshan/Desktop/lawyer.txt";
File textFile = new File(fileName);
Scanner in = new Scanner (textFile);
while(in.hasNextLine()){
[code]....
so it will read any text file dynamically and output to the text pane in interface. I think scanner code must be execute after the select the file from the browser and set the scanned result in to variable. then later out put the var as string in some jswing component?
View Replies
View Related
Oct 29, 2014
how to change the color of an output element in Eclipse? Can't seem to find it anywhere on the internet.For example, a response to my question 'What color do you want?' could be 'red'. I added an if-statement, which states if input = red, start using a red colored 'X' as string for further output.How do I obtain the color red for my X?? Or isn't it possible changing the color of output elements?
View Replies
View Related
Mar 21, 2015
By using FileReader, FileWriter and their constituents, I am creating a file to contain employee information ( name, age, hours, etc. ). The user is to input all of the data on a single line and we were asked to implement StringTokenizer to assign that data to the file. I have never used the StringTokenizer before, but I have a rough idea how it is to function. I used pw.println to test what I have so far, now I would like to let the user build the initial file with the "first employees" of the company, and then view the file, and then go back and append new employee data to that same file. My question is, how can I take the user input as a StringTokenizer and add that to the file?
In the for loop below, I thought I would see if it would work, but it does not. The loop only executes once and does not allow me to enter data.
public class Records {
public static void main(String [] args) throws IOException {
Scanner input = new Scanner(System.in);
FileWriter fw = new FileWriter("dbs3.java");
BufferedWriter bw = new BufferedWriter(fw);
PrintWriter pw = new PrintWriter(bw);
System.out.println("NEW EMPLOYEE DATA SHEET");
System.out.print("Number of new employees: ");
int number = input.nextInt();
[Code] ....
View Replies
View Related
Aug 8, 2014
I am trying to make a method that takes in a cmd command (nslookup, systeminfo, etc), and outputs the response to a text file. I have tried a dozen different ways with no success. below is my most current failure. It succeeds when i run it, but nothing shows up in the text file.
public static void runSystemCommand(String command) {
command = "ping 192.168.1.3";
try{
Process proc = Runtime.getRuntime().exec(command);
InputStream in = new BufferedInputStream(proc.getInputStream());
OutputStream out = new BufferedOutputStream(new FileOutputStream("C:NetPanelDataping.txt"));
[Code] ....
View Replies
View Related
Feb 12, 2014
I need to search a txt file for a specific keyword and then output all the lines that contain that keyword. Right now I I think I have my search done but I don't know how I would print the whole line.
TextIO.readFile("xxx.txt");
String search;
String word;
int count=0;
TextIO.put("Please enter your search word: ");
search = TextIO.getln();
while (!TextIO.eof()) {
word = TextIO.getln();
count = count+1;
if (search.equalsIgnoreCase(word)==true){
TextIO.put(count + "-");
TextIO.put(word);
Right now it doesnt even let me enter in any values for the search. Not sure what I've done wrong..
View Replies
View Related
Feb 9, 2015
So here we go with my problem:
- from the main class will arrive three variable (String name_used, int level_choose, int level_result)
I have a .txt file with this kind of formatting:
mario 1 1 0 1 0 1
carlo 0 0 0 1 1 0
...
Where I use 1 and 0 in the main for write if the level (you see that the numbers are always sixr? are egual to six level existing) BEFORE is done correct or wrong
- when in the main a user make a level a feedback coming back from the class level saying if the user made the count correctly or wrong. and i wanna replace the value (1 or 0) in the txt file with the new level result.
So i have all what i need as parameters i think.
name_used to look for the correct line in .txt file with .indexOf
level_choosed to go throught the correct index of that line
level_result (1 or 2) to be replaced with the existing one
Java Code:
public void salvaRisultati(String name_used, int level_choosed, int result_of_level) throws FileNotFoundException{
}
} mh_sh_highlight_all('java');
View Replies
View Related
Jun 22, 2014
I am having a lot of trouble with this lab. basically I have to make a text processor to read in code put it into a file and output the contents of the input file in alphabetical order one word per line. I have to reference the string varaibles input_filename and output_filename.
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
import java.io.File;
public class TextProcessor {
[Code] ....
these are the guidelines to said lab:
1. In the main method define two Strings called input_filename and output_filename. I will be setting these Strings to my own file names for testing your code, so make sure you get these variable names correct, and that you use them properly in the following steps.
2. Read in the text contents of the file referenced by input_filename.
3. Split the contents of the input text into separate tokens, using whitespace as a delimiter.
4. Lower case the tokens.
5. OPTIONAL: remove punctuation
6. Alphabetize the tokens.
7. Using output_filename, write the alphabetized tokens to an output file, one token per line.
8. Be sure to close file streams - no resource leaks!
9. Use methods to separate functionality in your program where possible
View Replies
View Related
Feb 5, 2015
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class array
{
public static void main(String[] args)
[Code] ...
Is there a way to write this, where, alpha is one array.
Write a program that declares an array "alpha" of 50 elements of type "double". Initialize the array so that the first 25 elements are equal to the square of the index variable and the last 25 elements are equal to three times the index variable. Output the array so that 10 elements per line are printed.
If I have an array of 50 integers, can I break that to read in lines of 10?
View Replies
View Related
May 29, 2014
Write a program that reads in a line of text and then outputs that line of text first in all uppercase letters and then in all lowercase letters.
INPUT and PROMPTS. The program prompts for a line of text as follows: "Enter the text: " and then reads in an entire line of text as a String .
OUTPUT . There are four lines of output . The first line is "The text in all upper case is: ". The second line is the line that was read in, displayed in all uppercase. The third line is "The text in all lower case is: " and the fourth line is the original line that was read in, displayed in all lowercase.
CLASS NAMES. Your program class should be called ShoutAndWhisper.
This is what I have so far:
import java.util.Scanner;
public class ShoutAndWhisper
{
public static void main(String[] args)
{
Scanner scannerObject = new Scanner (System.in);
System.out.println("Enter the text: ");
scannerObject.next();
System.out.println("The text in all upper case is: ");
View Replies
View Related
Jan 24, 2015
I am trying to write to a file but everything I have tried doesn't seem to work. What I want to do is read a file and then output back to the same file on a new line. The text file contains the sentence "Java is a programming language".
import java.util.Scanner;
import java.io.*;
class HW1B {
public static void main(String[] args) {
Scanner fileIn = null;
try {
fileIn = new Scanner (new FileInputStream("text.txt"));
[Code] ....
These are the errors :
HW1B.java:19: error: no suitable constructor found for Scanner(FileOutputStream)
fileOut = new Scanner (new FileOutputStream("text.txt"));
^
constructor Scanner.Scanner(Readable) is not applicable
(argument mismatch; FileOutputStream cannot be converted to Readable)
constructor Scanner.Scanner(InputStream) is not applicable
[Code] ....
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
2 errors
View Replies
View Related
Jul 20, 2010
i want to create a program in java which counts the number of prints taken from a printer..
View Replies
View Related
Jun 28, 2014
the number of lines that can be printed on a paper size, the point size of each character in a line, whether lines are double-spaced or single-spaced,the top and the bottom margins of the paper. assume that all characters are of the same point size, and all lines are either single-spaced or double-spaced. note that 1 inch = 72 points. make over, assume that the line are pointed along the width of the paper. for example, if the length of the paper is 11 inches and the width is 8.5 inches,then the maximum length of a line is 8.5 inches.write a program that calculates the number of characters in a line and the number of lines that can be printed on a paper based on following input from the user.
a.the length and width, in inches, of the paper.
b.the top, bottom, left, and right margins.
c.the point size of a line.
d. if the lines are double-spaced, then double the point size of each character
View Replies
View Related
Jun 24, 2014
I am trying to have a user select from a printed out array list, instead of having the user type in the "bill type" each time there is a bill to avoid user error as much as possible. For example I would like to have it print out like this:
"Select bill type from list:
1. Rent
2. Car
3. etc..."
and I would like the user to choose a number and not type in the "bill type". I don't want to use "Switch case" because it would need to be an expanding and I don't think "switch case" can do that.
Here is the code:
package homebudget;
class Spending
{
//Do i need a totalAmount variable?
String type;
double amount;
int year, month, day;
public Spending()
[Code] ....
case 2:
//Give option to enter a new expense or pick from list.
//How to do this? If Statement that doesn't list duplicates, or a while search?
resp = JOptionPane.showInputDialog("Enter the type of expense:");
type = resp;
resp = JOptionPane.showInputDialog("Enter the amount of the expense:");
amount = Double.parseDouble(resp);
[Code] .....
View Replies
View Related
May 27, 2014
Sometimes a nullpointerexception is thrown, in some cases null is easily printed as a value of a variable without an exception being thrown.
View Replies
View Related
Jun 30, 2014
Code in the book is written exactly like this:
import java.util.Scanner;
public class AdditionQuiz {
public static void main (String[] args){
//Generate random two integers using utility System.currentTimeMillis
int n1 = (int)(System.currentTimeMillis() % 10);
int n2 = (int)(System.currentTimeMillis() / 7 % 10);
[Code] ....
however the true/false result can not be printed due to the "answer" variable...
View Replies
View Related
Jul 23, 2012
I learning java an created the following servlet. The only problem is it printed to the browser as text instead of html..
It literally printed like this.
<html>
<HEAD><TITLE>Hellow World</TITLE></HEAD>
<body>
This STUFF IS WORKING!!!!!!!!!!!!!!!!!!
</body></html>
Why???
This is the servlet I created.
package sample;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloWorld extends HttpServlet {
[Code] ....
View Replies
View Related
Nov 21, 2014
I have wrote this class who read from text line by line and save the words in fileOnTable.. Now i don't know what to read in ReadOffer to save the words in object offers and return this.. One more question.. What JUnit test can write for this code..?
package com.example.crazysellout.UserSide;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
[Code] ....
View Replies
View Related
May 5, 2014
My requirement is to find the line number using multiline string. Here I need to extract the string between FROM and where clause(from the below string) and need to find the line number in the file
SELECT HL.LOCATION_ID,HPS.PARTY_SITE_ID,HCAS.CUST_ACCT_SITE_ID
INTO LN_SITE_LOCATION_ID,LN_LOC_PARTY_SITE_ID,LN_CUST_ACCT_SITE_ID
FROM HZ_LOCATIONS HL,
HZ_PARTY_SITES HPS,
[Code]....
View Replies
View Related
Sep 10, 2014
Write a program that accepts the line number from the user and prints only that particular line from the Floyd triangle.
Example:
Input: 2
Output: 2 3
Input: 3
Output: 4 5 6
View Replies
View Related