Error - Formatting Output String
Sep 28, 2014
I have this error that keeps coming up any time I select one of my buttons. It actually doesn't hinder the performance of the project, everything works. But I am concerned I missed something and errors are never a good sign.On a slightly different note, I would like to figure out what the best way to format my output would be? I would like it to display as "100.00 F". I have a couple ideas on how to get the F symbol (or other symbol) by inserting something like
String degreesymbol = "F" or whichever it is and then returning that in the output string later. I can't get the decimal formatted correctly and I don't know how to print the degree symbol.Here is the code
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;
[code]....
View Replies
ADVERTISEMENT
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
Jan 23, 2015
I am just learning arrays or rather teaching myself about them and I am not to sure how they work and why. I understand that in order to set one up you do
int[] example1;
example1 = new int[]{01, 02, 03, 04};
But I don't really understand is why if you only need 3 data integers, why put the 4th one in?
Also with outputting data, I understand .print() and .println() but I am not to sure what .printf() does and then the formatting after that.
System.out.printf("%3d%11") // and then what you want to print
View Replies
View Related
Nov 7, 2014
I've been trying for a while to get my exception output to print in a particular form to System.err.
What I'm looking for as output is
KeywordException: edu.cofc.csci221.KeywordException: **Keyword Not Found**
I'm getting
Keyword Exception: edu.cofc.csci221.KeywordException
at edu.cofc.csci221.CheckLine.checkForInvalidKeyword(CheckLine.java:101)
at edu.cofc.csci221.ReadLogFile.main(ReadLogFile.java:47)
The code:
line = scan.nextLine();
try { check.checkForInvalidSymbols(line); } catch (SymbolException sEx) { System.err.print("Symbol Exception: "); sEx.printStackTrace(); }
try { check.checkForInvalidKeyword(line); }catch (KeywordException kEx) { System.err.print("Keyword Exception: "); kEx.printStackTrace(); }
if(check.checkFirstKeyword(line) && line.split(" ")[0].equals(keywords[0])) { System.out.println(line); }
[Code] ....
I'm just unsure of where to go/what to do.
View Replies
View Related
Apr 25, 2014
So I want to format my output in a table much like the one in the book. I have an SECTable class and it displays the table one row at a time. 4 of the rows are in the 2D array in the SECTable class. The decimal position values are just displayed via a loop going from 12 to 1 (8 bits), 21 to 1 (16 bits), and 38 to 1 (32 bits) and the binary position values have their own class which contains an ArrayList of the binary position values as strings. Here's an example of how I want the table to be formatted (this is after an error has been generated so all the rows will be displayed):
Binary Position: 1100 1011 1010 1001 1000 0111 0110 0101 0100 0011 0010 0001
Decimal Position: 12 11 10 9 8 7 6 5 4 3 2 1
Stored As: 0 0 1 1 1 0 0 1
Check Bits: 0 1 1 1
Fetched As: 0 0 1 0 1 0 0 1
Error Check Bits: 1 1 1 0
And I need it to format similarly for 16 bits and 32 bits as well. Here's the display function for the list of binary position numbers:
public void displayList() {
System.out.print("Binary Positions: ");
for (int i = (posNums.size() - 1); i >= 0; i--) {
System.out.print(posNums.get(i) + " ");
}
}
Here are the display functions for the rows (separated them so that there wasn't so much code in one function):
public void displayTable() {
// Print the Binary Position Values
displayBinPositions();
// Print decimal bit positions
displayDecPositions();
[Code] ....
The print3rdRow and print4thRow are booleans to determine whether an error has been generated yet (user chooses from menu to create an error and the program picks a random bit to change and the erroneous data is put in the 3rd row and it's check bits are put in the 4th row). I tried doing spaces but it just wouldn't come out like I wanted.
View Replies
View Related
Sep 28, 2014
I am also having trouble with another program.
Java Code:
import javax.swing.JOptionPane;
import java.util.*;
import java.text.DecimalFormat;
import java.util.StringTokenizer;
public class ShelbyHarms_3_03 {
public static void main (String [] args) {
double a, b, c; //Input sides of triangle
double x; //Perimeter of triangle
double area; //Area of triangle
[Code] .....
Here are the errors:
ShelbyHarms_3_03.java:39: error: variable x might not have been initialized
JOptionPane.showMessageDialog(null, formatter.format(x));
^
ShelbyHarms_3_03.java:42: error: variable area might not have been initialized
JOptionPane.showMessageDialog(null, formatter.format(area));
^
2 errors
Am I not formatting the decimal format right?
View Replies
View Related
Dec 30, 2014
I am currently working on a project that can save text from a JTextArea and also open that same saved text. The problem I am having is that when I open the saved text file it is no longer formatted.
How the file looks before saving/closing:
public class HelloWorld{
System.out.println("Hello World!");
}
How the file looks after being saved/closed then opened:
public class HelloWorld{ System.out.println("Hello World!");}
When I save the file I'm actually saving the entire thing to a single string. When I do this the String eliminates all tabbed spacing and pushes all characters to one single line.
The only ideas I had for fixing this were to either somehow use Format in the String class or record every time user tabs and add to the String.
View Replies
View Related
Sep 18, 2014
double a = scan.nextInt();
double b = scan.nextInt();
double c = scan.nextInt();
//**********************************Equations**********************************
System.out.println ();
double sum = a + b + c;
System.out.printf("Sum = %d", sum);
Heres the error I'm getting
Enter three positive integers separated by spaces, then press enter:
15 20 9
Sum = Exception in thread "main" java.util.IllegalFormatConversionException: d != java.lang.Double
at java.util.Formatter$FormatSpecifier.failConversion(Unknown Source)
at java.util.Formatter$FormatSpecifier.printInteger(Unknown Source)
at java.util.Formatter$FormatSpecifier.print(Unknown Source)
at java.util.Formatter.format(Unknown Source)
at java.io.PrintStream.format(Unknown Source)
at java.io.PrintStream.printf(Unknown Source)
at project2.main(project2.java:52)
View Replies
View Related
Nov 28, 2014
I'm doing to create miles/kilometers converter. If I put the mile, converting to kilometer is right. However, if I put the kilometer, converting to mile comes out wrong value. Which part is wrong?
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
[Code] .....
View Replies
View Related
Oct 5, 2014
why the output is not giving the proper result? Is this a semantic error?
public class Programming1Practice {
/* testing out instantiation and object oriented programming */
public static class staticValues {
[Code]....
View Replies
View Related
Jan 22, 2015
I made a web app to test the ServletContextListener in tomcat according to the book head first servlets and jsps and used the code
out.println("test context attributes set by listener<br>");
Dog dog = (Dog) getServletContext().getAttribute("dog");
out.println("Dog's breed is: "+dog.getBreed());
in the listener class.But the output is showing the first line only and the second println() is not showing any output whereas my Dog class compiled successfully and I didn't see any NullPointerException as expected in the book but somehow it seems like the problem is in the 2nd line of code only but I don't know what.
I also tried to add a 4th line at the end with println() only but with a simple text even that is not running but when I put that same line after the 1st line, the output is shown.I am unable to see what has gone wrong in the 2nd line of code.
View Replies
View Related
Feb 25, 2015
How do I put this code in a way that it works because I know it is probably something obvious but I cant find how to make the array readable without error. It is supposed to intake two values and output what day of the week it is.
Testing Program
Initial day: Monday
Next day: Tuesday
Next day again: Wednesday
Previous day: Tuesday
Next week: Tuesday
Add 4 days from initial day: Friday
[Code] ....
ERROR ; Days.java:5: error: class, interface, or enum expected
String[] days = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
^
1 error
View Replies
View Related
May 15, 2014
Problem: On the form window, after pressing the button, it doesn't give any error and doesn't give any output. It doesn't reply and i have to stop compiling to exit. Why does the IDE do that, is it about my Java codes or Form Window codes ? ( I have two classes named Lexical.java and window.java. Working with Eclipse)
Details: I am working on a project that makes Lexical and Syntax analiysis of commands written in SQL Language. My form is in the attachment. If will be necessary i'll put my codes too.
Attached image(s)
View Replies
View Related
Oct 2, 2014
I have to create a program that uses the Scanner in String input and Output that will enable the user to convert
double -> int
int -> byte
int -> short
int -> hex-string
The output should look something like this:
Syntax: convert <value> <type>
convert 15.5 int~> 16
convert 128 byte~> -128
<type>: int, byte, short, hex, decimal
Syntax: max <type>
max byte~> 127
<type>: int, byte, short
[Code] ....
View Replies
View Related
Oct 14, 2014
What it is supposed to do is decide whether a ceiling fan is on or off, and describe it (color, area, speed). This is all user input (even pi) so it should decide whether to turn it on or off but for some reason skips over my if/else if statements all together.
I've tried changing it around a bit, looking up what my problem may be but this problem remains the same. my code:
import java.util.Scanner;
public class CeilingFan
{
final int slow = 1;
final int medium = 2;
final int fast = 3;
private int speed;
boolean on = false;
private double radius = 5;
private double pi = 3.1415;
String color = "blue";
[code]....
View Replies
View Related
Jan 6, 2014
I have written the code:
Java Code:
public static void main(String[]args)
{
Scanner input = new Scanner(System.in);
System.out.print("Type your text: ");
String text = input.nextLine();
int counter = text.length();
if(text.length()> 16)
[Code] ....
And input is: abcdefghijklm
output is:
Java Code:
a b c d
e f g h
i j k l
m x x x mh_sh_highlight_all('java');
So all i want is, if i type: abcdefghijklm
I want this output:
Java Code:
a e i m
b f j x
c g k x
d h l x mh_sh_highlight_all('java');
View Replies
View Related
Jan 28, 2015
I have a assignment to do some Lexigraphic ordering. I have figured how to get the majority of this done, however, when I input my string values. No output takes place? :s
import java.util.Scanner;
public class Lab03c {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner lexi = new Scanner (System.in);
String s1,s2;
[Code] ....
View Replies
View Related
Jan 5, 2014
Following is the code for my assignment where a user inputs his full name in a string from keyboard. It should be done using BufferedReader. The program will give his initials as output.
############################
For example: User inputs-> Ram Kumar Das
Program Returns-> R.K.D.
I am written the following piece of code. It does not return the correct output. If "Ram Kumar Das" is given as input, it gives R.K.K. as output. Arrays and objects are strictly not allowed.
Java Code:
import java.io.*;
public class Assignment
{
static int i=0;
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public static void main (String args[]) throws IOException
[Code] ....
View Replies
View Related
Jan 25, 2015
public class op{
String word = "Hello"; //my variable
public void reverseword() //My function {
for(int i =word.length();i>=0 ;i--) {
System.out.println(word.charAt(i));
[code]....
when i call function in main i have this error:
run:
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 5
at java.lang.String.charAt(String.java:658)
at javacourse.Car.opname(Car.java:35)
at javacourse.JavaCourse.main(JavaCourse.java:24)
Java Result: 1
View Replies
View Related
Jan 29, 2014
Below is my first ever code. I bolded where i am getting a syntax error. Why am i getting an error here if i assigned that word to a string?
public class BeerBottleTest {
public static void main(String[] args) {
int beerNum = 99;
String bottle = "bottles";
while (beerNum > 0) {
if (beerNum == 1) {
bottle = "bottle"; }
[Code] ....
View Replies
View Related
Jul 21, 2014
I am currently trying to split the string "EAM est" between the part. I have gotten the code to work if the was a -. But I can't see why the error is occuring
I have tried
String test = "EAM-testing";
String[] parts = test.split("-");
System.out.println("parts[0] = " + parts[0]);
System.out.println("parts[1] = " + parts[1]);
String test1 = "EAM esting";
String[] parts1= test1.split("");
[Code] .....
The error occurs at line: String[] parts1= test1.split("");
View Replies
View Related
Jul 1, 2014
I'm writing basically my first program for school. I've written small ones, following instructions, but this is the most vague. I'm having issues. I can't figure out what the error means. I'm not done with the code, but I think the ArrayList is throwing me off. I'm trying to gather user input and sum the total. Here's the code:
package graduationplanner;
import java.util.ArrayList;
import java.util.Scanner;
import java.lang.Double;
public class GraduationPlanner {
public static void main(String[] args) {
[Code] ....
View Replies
View Related
Nov 18, 2014
I'm having a small error with my code, it is getting rid of the first letter of the string after the first line printed.
import java.util.*;
public class PrintPyramidName {
public static void main(String[] args) {
System.out.println("What is your name?");
Scanner input = new Scanner(System.in);
[Code] ....
View Replies
View Related
Jul 25, 2014
this method is supposed to compute the decimal value of an entered binary the first 2 lines are causing a string out of index error.
public static int computeDecimalValue(String num)
{
int end = num.length();
[Code]....
View Replies
View Related
Jul 2, 2014
I write a code but it show a error message
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String ind
ex out of range: 10
at java.lang.String.charAt(String.java:658)
at StringChar.main(StringChar.java:11)
Code :
class StringChar{
public static void main(String ss[]){
String str="HelloWorld";
int a;
System.out.println("String is = " + str);
a=str.length();
System.out.println("String is After Reverse");
for(int i=a;i>=0;i--)
System.out.print(str.charAt(i));
}
}
View Replies
View Related
Apr 16, 2015
I am having issues with the program below everything works but I can't figure out a way to add code that if a user just hits enter without inputting anything it says "entering in nothing is not a valid choice" I am stuck on how to compare a int to a string ...
//import statements
import java.util.*; //for scanner class
// class beginning
public class Guess {
public static void main(String[] args ) {
//Declare variables area
[Code] ....
View Replies
View Related