Output Is Not Giving Proper Result - Semantic Error?

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


ADVERTISEMENT

Finding Longest Increasing Sequence Not Giving Proper Result

Jan 28, 2015

Okay so I need to be able to read a file and then be able to find the longest sequence of increasing numbers.

So if the file was this, (this is Ass1Q2_test4.txt)

97 47 56 36 60 31 57 54 12 55
35 57 41 13 82 80 71 93 31 62
89 36 98 75 91 46 95 53 37 99
25 45 26 17 15 82 80 73 96 17
75 22 63 96 96 36 64 31 99 86
12 80 42 74 54 14 93 17 14 55
14 15 20 71 34 50 22 60 32 41
90 69 44 52 54 73 20 12 55 52
39 33 25 31 76 45 44 84 90 52
94 35 55 24 41 63 87 93 79 24

the output should be,

(5,0) with cost 12
(6,0) with cost 14
(6,1) with cost 15
(6,2) with cost 20
(7,2) with cost 44
(7,3) with cost 52
(7,4) with cost 54
(6,3) with cost 71
(5,3) with cost 74
(4,3) with cost 96

Greatest path is of length 10.

Now, the code that I have works, kind of. Instead of recurring several times at each point, it only recurs once.

So say I'm looking at (1,1). With (1,1) being 57. The area around it looks like this.

97 47 56
35 57 41
89 36 98

Now when I look at it, there are several paths it can take. It can go 57, 97 or 57, 89 or 57, 98. However, I'm pretty sure that it just uses the first one that corresponds with the first if statement that is valid. So I start checking north of the value, then northeast, then east, then southeast, which at southeast is where I find my first greater than value. After it finds it's first valid number, it then continues from that number, instead of checking if there are other longer paths stemming from the original value.

In conjunction with that, you can see that the printout just returns all paths from each value. Which isn't what I want. I need a way to store the longest current path, then check each path after to see if it's longer. If it is, it's replaced, if not, it stays the same.

I've also attached Ass1Q2_test4.txt

import java.util.*;
import java.io.*;
public class MaxIncreasingSub {

[Code].....

View Replies View Related

Java Swing- After Pressing JButton It Is Not Giving Error Nor Output

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

Stack - For Loop Not Returning Proper Result

Jul 18, 2014

Below is a method that is suppose to insert a value inside a stack based on the index. I thought it would be easier to copy the value, if any, that was in the index into the variable holder and replace it with the input value. After in which it would copy the holder value and place it at the top of the stack. (topOfStack variable is what the holder is copying too.)

public void pushExact (int index, String input) {
String holder = "";
if (maxSize == 0) {
theStack[topOfStack] = input;
topOfStack++;
} else if (topOfStack + 1 < maxSize) {
for (int n= maxSize - 1;n >= 0;n--) {

[Code] ....

View Replies View Related

Semantic Error In Hexadecimal Converter

Jun 29, 2014

I'm sure the solution is simple, but I cannot find it.

/*reads a hexadecimal number input by the user and gives the corresponding base-10 value
*/

public class HexConverter
{
static int i; //used to keep place in the hexadecimal sequence given by user
public static void main(String[] args) {
//declaration of variables
String hexgiven; //the hexadecimal sequence given by user

[Code] .....

View Replies View Related

Numbers Divisible By 6 - Code Is Giving Different Result Then Expected

Aug 22, 2014

I am having problems with writing a simple program to see if a number is divisible by 6.

public void run() {
println("This program will display all numbers divisible by");
println(" 6 between 1 and 100.");
int x =1;
boolean divide =(x%6==0);

[Code] ....

It is telling that every number is not divisable by 6?

View Replies View Related

Simple Program Giving Negative Result For Amount Of Calculations Done

Mar 5, 2014

Why this extremely simple program seems to be giving me a negative value for amount of calculations done within one minute ( Just using it as a bit of fun to see how different computers in the office perform).

Java Code:

class Benchmark {
public static void main(String[] args) {
long endTime = System.currentTimeMillis() + 60000;
int count = 0;
for (int i = 0; System.currentTimeMillis() < endTime; i++) {
double x = Math.sqrt(System.currentTimeMillis());
count = i;
}
System.out.print(count + " calculations per minute");
}
} mh_sh_highlight_all('java');

I am getting results between -2.1billion and -3.4billion which to me would make sense since they are not the best computers in the world but I would be expecting a positive value?

View Replies View Related

Output Giving Question Marks?

Feb 6, 2015

I am testing a code given by my lecturer and the output it gives me are all question marks? Heres the code:

package assignment;
import java.util.Random;
public class DeckOfCards { // begin DeckOfCards data type

// playing cards of deck of cards
private PlayingCard[] deck;

[code]....

View Replies View Related

Infile Output - Only Giving One Name Two Times

May 7, 2014

I am having issues with the first part of my program. When I got to display what is in the textfile, it only gives me one name two times. I cannot figure out what to do with my outer loop in order for it to read and output the entire data file.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.*;
import java.util.Scanner;
import java.io.*;
import java.text.*;
import java.math.*;
import java.util.StringTokenizer;

[Code] ....

View Replies View Related

Why Java Is Giving Error For Symbol

Sep 28, 2014

I am having trouble figuring out why java is giving me an error for the symbols. I will post the errors below the code.

Java Code: import java.util.Scanner;
public class ShelbyHarms_3_02 {
public static void main(String[] args) {
Scanner console = new Scanner(System.in);

[code]....

View Replies View Related

JavaFX 2.0 :: App Hangs Without Giving Any Error Information

May 6, 2015

I have an app that is randomly hanging it doesn't give any error information when it hangs.
 
Is there at way to see what's going on when it hangs? e.g. the methods that are being called, where is the program execution at..

View Replies View Related

How To Print Result Of Program In Output File

Mar 17, 2014

I have printed the result of my program into an output file.

For some reason I can't figure out how to get the file output.txt to actually print.

I've tried printing it like I would normally print a file but it's not working.

Java Code:

final PrintStream console = System.out;
File file = new File("output.txt");
PrintStream out = new PrintStream(new FileOutputStream(file));
System.setOut(out);
System.out.println(collection.toString());
System.setOut(console);

What do I do after this? mh_sh_highlight_all('java');

View Replies View Related

Java Runtime Get Result Output From Prompt / Large File - Process Will Hang

Aug 13, 2014

I am using java process to start a system command in windows

Runtime r = Runtime.getRuntime();
Process pr = r.exec(cmdString);

I want to get the prompt out put from cmdString = "cmd /c type fileSmallSize"->>>> It is ok the have the content of the file when file is small.

However, for a large file java process will hang and no Exception occurred, what is the problem?

The easiest testing you can try on the logging.properties file in java.

public static String executeCmdAndReturnPromptResult(String cmdString)
throws Exception {
LOGGER.entering(CLASSNAME,
"Entering executeCmdAndReturnPromptResult()", cmdString);
String cmd = cmdString;

[Code] ....

It seemed to me that the bufferSize is limited so that I can only have it less than a default one, how to increase it?

My question now is how to increase the size of buffer in order to read a larger InputStream ?
BufferedInputStream() default size is
private static int defaultCharBufferSize = 8192;
private static int defaultExpectedLineLength = 80;

How to make it larger and working? I tried to increase the defaultCharBufferSize to 500000000 but it did not work!

View Replies View Related

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 View Related

Output Error About Converter (Miles / Kilometer)

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

Servlets :: No Error Shown While Compiling Java File But Also No Output

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

Intake Two Values And Output - How To Make Array Readable Without Error

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

Not Getting A Proper Shape Of Leftarrow

Apr 22, 2014

why am I not getting a proper shape of "Leftarrow"? The result should look like the following (the system draws the arrow abnormally, so the beginning should a real ARROW:

*

* *

* *

* * * * * * * * *

* *

* *

*

here is the class:

Java Code: public class LeftArrow extends ShapeBase {
private int lengthOfTail;
private int widthOfArrowHead;

[Code]....

View Replies View Related

Could Not Find Proper Position In Print

Aug 3, 2014

So I need to print out the table of conversions from kilogram to pound and from pounds to kilograms. I think I have done a while loop correctly, but it is hard to actually check it since I do not have proper output format. I have tried also %4.2f format option however could not find the proper position in the print.

public static void main (String[] args){
System.out.printf("%10s%10s | %10s%10s
", "Kilograms", "Pounds",
"Kilograms", "Pounds");
System.out.println("---------------------------------------------");

[code]....

View Replies View Related

Proper Way To Organize Code Into Blocks

Feb 16, 2015

When I run this (entering 12 for both questions) I get this error:

java.lang.ArrayIndexOutOfBoundsException: 12
at MathTablesTwo.main(MathTablesTwo.java:22)

Also, what would be the proper way to organize my code into blocks?

import java.util.Scanner;
public class MathTablesTwo {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);

[code]....

View Replies View Related

JRE :: How To Create Proper Deployment Rule Set

Dec 2, 2014

I have a signed certificate from Entrust which I used to sign a DeploymentRuleSet.xml file.  I placed the DeploymentRuleSet.jar in the proper location C:WindowsSunJavaDeployment, afterward the java control panel's security tab shows a link to "show the active deployment rule set" which did not exist prior to coping the file to the directory.  When I click on the link a new window opens and says "Rule Set not found" ....

View Replies View Related

Physical Print Out For Bill In Proper Format

Sep 23, 2014

I am trying to take physical print out for bill, But i am receiving some problems:

Java Code:

import java.awt.Color;
import java.awt.print.PrinterException;
import java.util.ArrayList;
import javax.print.attribute.AttributeSet;
import javax.swing.JTextArea;
import javax.swing.JTextPane;
public class Printme {

[Code] .....

But My Output is

What i have to do / learn to get the proper bill format ....

View Replies View Related

Window Should Pop Up Giving Properties Of Javac

Feb 20, 2014

I have just tried to learn java this week [COLOR="#000000"]and I am being held back by this once installed java jdk I nav to the java file and the bin file and then the javac file to find that the below tab does not exist

A new window should pop up giving the properties of the javac, there should be an attribute called Location..I can see the location option in my documents but in no other folder

View Replies View Related

I/O Streams :: Insert Space At Proper Place By Breaking Sentence Into Correct Words

Nov 27, 2014

You are given 2 files - "testcase.txt" and "validwords.txt".In testcase.txt, the sentences are written without any space inbetween/for ex: this is a sentence which looks ambigous.You are to insert a space at the proper place by breaking the sentence into correct words, ex o/p: this is a sentence which looks ambigous.validwords.txt contains all valid words (as 1 word per line). If you find a word that does not match, replace it with ####. After correcting

View Replies View Related

Java Program Using Apache POI Giving Exceptions

May 13, 2015

I am having some serious difficulty getting my project off the ground. I have the following code:

FileInputStream file = new FileInputStream(new File("src/retestchecker/test_sheet.xlsx"));
//Get the workbook instance for XLS file
XSSFWorkbook workbook = new XSSFWorkbook(file);
//Get first sheet from the workbook
XSSFSheet sheet = workbook.getSheetAt(0);
Row row = sheet.getRow(0);
Cell x = row.getCell(3);
System.out.println(x);

Everything is properly imported, etc etc.. But I am getting this error and I am not sure what it means:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xmlbeans/XmlException
at retestchecker.RetestChecker.main(RetestChecker.java:23)
Caused by: java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlException
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)

[Code] .....

Java Result: 1

I am using Netbeans and the latest version of Apache POI that was released May 11, 2015.

The line 23 that the error refers to is this line:

XSSFWorkbook workbook = new XSSFWorkbook(file);

View Replies View Related

Random Generator Method Is Not Giving Correct Average?

Aug 4, 2014

Create an array that will store 7 temperatures.

Populate the array with 7 random temperatures from 1 to 100 degrees. (hint use a for loop and a Random number Generator)After the temperatures are in the array, calculate the average of the temperatures in the array.

Print out the average.Print out each temperature in a statement comparing it to the average such as:

The average temperature is 48.94

Temperature 1 is 5.0 and is below average.

Temperature 2 is 67.8 and is above average.

import java.util.Random; 
public class ArrayOfTemperatures
{
public static void main(String[] args) {
// Declare an array
int[] randomtemps = new int[7];
temps[0] = 45;

[code]....

View Replies View Related







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