Line Skipping And Not Allowing To Put Values In

Apr 21, 2014

I been working on this code for hours and for some reaon, a system.out.println skips and wont let me put values in. I dont know what is wrong.

Code :

import java.util.Scanner;
public class Alcaraz_Program2a
{
public static void main (String [] args)
{
byte tons;
short pounds;

[Code] ....

View Replies


ADVERTISEMENT

I/O - Read 11 Values From A Text File / Each Value On Separate Line

Mar 26, 2014

So I'm trying to read 11 values from a text file, each value on a separate line. The first value I use as loop control to run through calculations on the other ten and finally output both the numbers and the calculations to the console and an output file. I'm not getting a compiler error or a runtime error but my loop seems to stop after reading the first line. It also doesnt seem to be writing to my output file but does create it when I run the program. This is what my text file looks like

10
150.4
88.4
-3.14
499.4
799.4
1299.8
0
1900.2
901.7
4444.4

This is what my program looks like

import java.util.*;
import java.io.*;
 public class assignment7scratch
{
  Toolkit_General toolKit = new Toolkit_General();
  public static void main (String[]args)throws IOException

[Code] .....

so I dont get an error but this is what my output looks like

----jGRASP exec: java assignment7scratch

This program reads a list of values representing number of miles driven by individuals. It will output the dollar amount their rental cars cost.

Number of miles traveled on the left as well as amount reimbursed on the right

-----------------------------------------------
Miles Driven Amount reimbursed
150.427.072

----jGRASP: operation complete.

it also doesn't write anything to my output file, though it does create one.

View Replies View Related

Allowing User To Input Until They Want Exit

Aug 18, 2014

/* Jessie Garza
* 08 / 18 / 14
* ModCalculator
*/

import java.util.Scanner; // program uses Class Scanner
import javax.swing.JOptionPane;
public class ModCalculator
{
// main method begins execution of Java application

[code]....

I am having troubles with allowing the user to input operations/digits until they want to exit, I have tried looping, but I was unsuccessful, came here hoping to figure this out.Currently I have it ending with Break statements after each switch so that they don't coincide all together.. I can't figure out how to keep the Break statement AND loop to previous code of System.out.println( "Please enter an operand which you would like me to calculate with :");

String st = input.next();
c = st.charAt(0);
System.out.println( "I will need for you to input two integers and I will output the result.");
System.out.print( "Enter first integer to calculate: " ); // prompt
number1 = input.nextInt(); // read first number from user
System.out.print( "Enter second integer to calculate: " ); // prompt
number2 = input.nextInt(); // read second number from user

and allowing it to run through the rest of the program with the options still in tact, while having an if statement of an exit keyword.

View Replies View Related

Allowing User To Determine When A Program Is Stopped?

Nov 8, 2014

I was tasked with building a program that counts vowels in a phrase or word. I have this working properly, but the problem arises in the next situation. Here is my code:
 
Scanner userInput = new Scanner(System.in);
int userDecision;
String Choice;
String Phrase;
int vowelCount = 0;
System.out.println(" This program will count the number of vowels in it.

[Code] ....

As you can see, I used a 'for' statement to declare how long the program should run. However, I need the user to be able to say when it ends. For example, at the end of the program it must say "There are ______ number of vowels in your word. Please press '1' to run the program again, or any other number to exit."

I understand a do-while loop is needed here, but every time I try and create an adequate loop with no logic errors, I either break my existing code, or the program does not work correctly.

Basically, my question is, what is the best way to perform this task? Is a do-while loop necessary, or is there a better way?

View Replies View Related

Allowing User To Input A Number And Assign This To Int Variable

Jul 4, 2014

I need the user to be able to input a number, and for the program to assign this value to an 'int' variable. I know how to do this with a 'string' variable:

Java Code:

String options = JOptionPane.showInputDialog(null, "In your decision, how many options do you have?
" +" (NOTE: The maximum number of options = 5, and you must enter your answer as a numeral.)"); mh_sh_highlight_all('java');

But I need to know how to do this with an 'int' variable.

View Replies View Related

Allowing A User To Enter X Number Of People Into Array

Feb 5, 2014

I am starting a program that is dealing with arrays. My issue, allowing a user to enter 'x' number of people into an array. How do I first allow them to enter the size of an array, and then enter strings (list) into that array. In addition to this, I need to specify the number of boxes of cookies sold by each person and keep a tally of the number of people selling cookies in each category (e.g. 1-10, 11-20...etc). Instead of having a number 100000, I want the user to enter that size, 'x'.

import java.util.Scanner;
public class cookie {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int x = 100;
double saleCount[] = new double [x];
String[] girlScout = new String[100000];
 
[code]....

View Replies View Related

Skipping While Loop After First Run

Dec 11, 2014

I need to add a kb.nextLine(); somewhere but I've tried adding it after nextInts and it hasn't worked. The problem is in the test.

public class Account{

//instance variables
private static double annualInterestRate;//this is the class variable
private int id;
private double balance;
private java.util.Date dateCreated; //creates an object from the date class in java

[code]....

View Replies View Related

Skipping Else If Statement

Jun 5, 2014

I have two different Class object arrays storing 3 elements (2 Store arrays, both initialised to hold 3 Product objects). The problem is, I can set data to one array with no problem but my program doesn't want to set the data for my second array.

For instance, The main problem is this method:

public void addData(String store, String newName, int newDemand, double newSetup, double newUnit, double newInventory, double newPrice)
//Method that sets the data value for a product
{
if (store.equalsIgnoreCase("callaghan"))//!!!!Goes from this line in the debugger
if (noOfProductsCallaghan==0)
{
setData(product[0], newName, newDemand, newSetup, newUnit, newInventory, newPrice);
noOfProductsCallaghan++;
}
else if (noOfProductsCallaghan==1)

[code]...

View Replies View Related

IF Statement Skipping To Else

Aug 1, 2014

I'm very new to java programming / programming in general and I'm having an issue.

When I execute this part of my code it does this.

Quote

Has this car been in an accident? (Y/N): Please enter Y/N

View Replies View Related

Skipping Further Prompts When Certain Conditions Are Met

May 1, 2014

Is there any way to skip the 2nd and 3rd questions in this instance if I input "exit" or make an error in the 1st input. Essentially skip over the "enter 1st number / enter second number" prompts and go straight to the switch statement? In the case of "exit" exit the program immediately without the prompts. If an error, loop around to the beginning without the further prompts.

import java.util.Scanenr;
public class Meddle {
public static void main (String args []) {
double n1,n2,answer;
Boolean check = true;

[code]...

View Replies View Related

Skipping Lines During Debugging

Dec 19, 2008

I'm working or better say.. I'm trying to work :) with Maven projects (m2eclipse plug-in) and Eclipse IDE. The problem I have is that sometimes the debugger seems to skip some lines of the code without a reason.

Is there an issue of synchronisation with my .class files?

View Replies View Related

Program Skipping Over User Input

May 19, 2014

So i'm just toying around with making a simple inventory system, and when i'm trying to get the user's input (first the ID number, then the item name, then the item price) it will take the ID number, output asking for the name (but not take any input for it) and then ask for the item's price. I'm really not sure why it's never happened to me before when getting user input.

This is the input part of my code:

public void getInfoAdd() {
int id;
String name;
double price;
System.out.print("Enter ID: ");
id = sc.nextInt();
System.out.print("Enter item name:");
name = sc.nextLine();
System.out.print("Enter desired price: ");
price = sc.nextInt();
addItem(id, name, price);
}

And this is what it outputs:

Quote
Enter ID: 2
Enter item name:Enter desired price: 40
Successfully added: 2 $40.0

View Replies View Related

JUnit Test - Read From Text Line By Line And Save Words In FileOnTable

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

I/O / Streams :: Find Line Number In A File Using Multi Line String

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

Floyd Triangle - Accept Line Number From User And Print Only That Particular Line

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

How To Make File Reader Object Move To Next Line If There Is No More Input On Line

Feb 18, 2015

How do I make the file reader object move to the next line if there is no more input on the line. Here is my text and output file as you can see that my text file column cuts off on the 2nd line after 70. I want to read that next line which is 100 into my labs variable however its reading it into my final exams variable. I'll also post the code but I didn't think it was necessary.

textfile:
100908095
1008070
10070

output:
Labs Projects Tests Final Exams
100908095
1008070100
70

[import java.util.Scanner;
import java.io.*;
public class MyGrades
{
public static void main (String[] args) throws IOException
{
int lab, project, test;
int finalExam;//Par and Player values

[Code]...

not sure if I code wrapped it correctly

View Replies View Related

I/O / Streams :: Reading A File Line By Line And Deleting It

Oct 15, 2014

If I want to read my file line by line and when it hits a certain value from that point it should start deleting the lines until the tag ends.Just curious will my code actually work at the moment or not because it goes through so many times then goes straight back to the variable declarations at the start of the method and never hits the console print line.

public void removeEnvironment(){
//declare variable to environment id
String environmentID = "Environment id";
String lines = null;
boolean lineFound = false;
boolean end = false;

[code]...

View Replies View Related

Find A String And Display Line Number And Line Itself?

Oct 20, 2014

I'm creating a program that searches a txt file for a given string, then return the number line and the line itself. However, my testFile class isn't detecting my searchWord methods.

The searchWord and recursiveSearch is written in a java class called BasicFile

public List<String> searchWord(String key) throws Exception {
LineNumberReader lnr = new LineNumberReader(new FileReader(f));
return recursiveSearch(lnr.readLine(), key, lnr);
}
public List<String> recursiveSearch(String currentLineText, String key, LineNumberReader lnr)

[code]....

Is it because I'm using a list instead of a string?

View Replies View Related

Scanning Next Line Of Input Without Advancing Past Line

Apr 12, 2014

I'm doing an assignment for uni and have come across a small hiccup. What I'm trying to do is scan in a text file and read "commands" for it line by line, E.g:

Student Mary 12345 19
Student Joe 12346 19
Change Joe 19 20
Change Mary 19 20

So that lines that begin with the word "Student" indicate that I should create a new student file with that name, student ID, and age.

"Change" indicates that I should be changing the specified student's current age to the new age etc.

What I'm currently doing is something along the lines of this:

Scanner input = new Scanner(new FileReader(args[0]));
String[] line;
while (input.nextLine().startsWith("Student")) {
line = input.nextLine().split("s+");

[Code] ....

The problem I'm having is that every second line seems to be getting skipped (because I'm calling nextLine() so much?) but I can't think of a way to "peek" at the first word of each line without advancing past it. Is there any way of doing this?

View Replies View Related

Read File Line By Line

Dec 8, 2014

how to read file line by line ? Namely my input file I want to read look as follow:

AAA 1, 1
12 222 12
AAA 2, 2
11 122 11
 
My output file should look as follow:

1, 1, 12
1, 1 222
1, 1, 12
2, 2, 11
2, 2, 122
2, 2, 11
 
I think the lines need to be stored in ArrayList, then I would like those lines to write to csv file, but how on read I can construct such output file? This is my code for reading file
  
public ArrayList readFile(String filename)
{
try
{

[Code]....

View Replies View Related

Pickup Selected Text File And Read Line By Line And Output Text Into Visual Text Pane

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

Store Pixels Values Currently On Screen And Compare Them To Values On The First Frame?

Aug 29, 2014

I need a way to store the pixels values currently on the screen and compare them to the values on the first frame. Right now I'm using glreadpixels as follows:

currentBuffer= BufferTools.reserveByteData(mapSize);
glReadPixels(mapStartX, mapStartY, mapWidth, mapHeight, GL_BLUE, GL_UNSIGNED_BYTE, currentBuffer);
for (int i = 0; i < mapSize; i++) {
if (currentBuffer.get(i) != baseBuffer.get(i)) {
//Do nothing
continue;
}
//Do something
}

This works perfectly fine but turns out to be a real bottleneck, dropping the fps to a third of what it was. Is there any quicker way? All I'm after is speed, I don't even need to show it on the screen if the comparison is made "behind the scene".

View Replies View Related

Servlets :: How To Send Multiple Values Of Same ID But Different Values Of HTML

Feb 27, 2015

I have a question in mind that this is my registration form. I am sending these values from HTML form to server and database. I have question that in my case if I click next to Add Another Mobile no in HTML.then a block is genereated and each time a new name is generated.

My Question is if I click 6 times then 6 name attribute are generated. How can I send and differentiate them on my server side.

Because at their I will use something request.getAttribute("Attr_Name");

But they are same. How to do this?.

View Replies View Related

Instead Of Different Values In Two Columns Per Row In Jtable Getting Same Values

Feb 5, 2014

I have a JScrollPane with two coulmns. In the first column I have an image pane JTable, and in the second a list with names of sections. This second column I try to divide in two columns, one (the second column) to display the names of the sections (each row contains one name), and in the other column (the third) I want to show some values for every section in the row respectively. But, instead of displaying the desired values in the third column, I get the same names of the sections as in the second column.

View Replies View Related

Passing Values To Two Classes And Retrieving Values From Those Classes

Feb 14, 2015

I'm doing an aggregation exercise that's suppose to find the volume and surface area of a cylinder. What I'm trying to do is pass values from one class, to a second class, and that second class passes values to a third class.

This may be a clearer explanation: The first class is the main program which sends values to the second and third class. The second class is used do calculations for a circle (a pre-existing class from another assignment). The third class grabs the values that the second class calculated and calculates those values with the one that was passed from the first class to the third class. The first class then prints the outcome.

Problem is when the program gets to the third class, it just calculates the value from the first class with the default constructor from the second class. It's like the second class never received the values from the first class. I think I'm missing a step, but I don't what it is.

First Class:

package circle;
import java.util.Scanner;
public class CylinderInput
{
static Scanner in = new Scanner(System.in);
public static void main(String[] args)
{
//user defined variable

[Code]...

View Replies View Related

Printing Same Line Twice?

Sep 24, 2014

I've been working on the below code for a couple days in my spare time. Just a simple little text-based RPG. I'm brand new at programming and Java, so excuse the bad syntax. There's probably easier ways to go about what I'm trying to accomplish, but all we've learned so far in class is while loops and if statements. Anyways, the problem is that the statement "Really? Ten health points[...]yes or no?" in my code is printing twice.

int health = 0;
boolean enterHealth = false;
String verifyHealth = "";
boolean test6 = false;
boolean test7 = false;
boolean test8 = false;

[code]....

View Replies View Related







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