While Loop Loops Forever Even With The Right Inputs

Sep 9, 2014

Why when the user enters Y or N, this loop still continues looping instead of quitting?

System.out.println("Enter Y to indicate Up OR N to indicate Down " + "
");
String option = scanner.nextLine();
 while (!response.equalsIgnoreCase("Y")||(!response.equalsIgnoreCase("N"))) {
System.out.println("Enter Y to indicate Up OR N to indicate Down " + "
");
option = scanner.nextLine();
}

View Replies


ADVERTISEMENT

Displaying Inputs To TXT File?

Oct 13, 2014

so far this is what i have written. The program works correctly but I need to be able to have the numbers i am entering to show up on the .txt file.

import java.util.Scanner;
import java.io.*;
public class LargestAndSmallest {
public static void main(String[] args) throws IOException {
Scanner input = new Scanner(System.in);

[code].....

View Replies View Related

Modifying Files Using Inputs From GUI

Feb 25, 2015

I want to work on a project in which I have a GUI where I can choose certain variables from drop down menus. I want to use these variables to modify a few configuration files. I have looked upon internet for a few methods which can be used for the same. However, I am not sure about the method I should use. The files I want to modify consist of 10 -15 lines.

View Replies View Related

Using User Inputs In Other Class?

Feb 8, 2014

I have a LoginScreen class and one other class in my project. I want use user inputs (Username And Password) on other class if users details is true. I am stcuk at this point because when user attempt to Login connection is succesfully and other frame is coming to screen but i can reach user details anymore. Let me explain with codes;

LoginScreen class

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package deneme3;
import java.sql.Connection;

[code]....

You can see Button Action in MainProgramWindow " System.out.println( ??? );" How i can retrieve users inputs from this class ?

View Replies View Related

Multiple Key Inputs Not Working

Sep 16, 2014

i am currently making a game in java and currently i am working on the basic mechanics. most of it is working fine but i cannot seem to make it so when the user presses and movment key and space to fire a bullet the bullet fires in the direction they are moving. here is the code i have for movement.

public void keyPressed(KeyEvent e) {
// TODO Auto-generated method stub
int bulletx = Player.x + 100;
int bullety = Player.y + 20;
int key = e.getKeyCode();
if( key == e.VK_W){
p.moveUp();
}
if(key == e.VK_S){
p.moveDown();

[code]....

View Replies View Related

Calculations On Text Box Inputs

Mar 7, 2014

I have made a simple form, it consists of 3 text box's textbox1, textbox2 and textbox3 as well as 1 button button1. What I want to be able to do is put numbers into textbox 1 and 2 and then show the multiplication of these numbers in textbox 3 when the button is pressed and I was wondering what is the standard way of reading these numbers from the text box and allowing us to do the conversion obviously in the textbox its a string and we need to convert to an int or double or whatever to be able to perform calculations on them then convert it back into a string to display in text box 3?

View Replies View Related

Sudoku Is Not Working For Few Inputs

Apr 22, 2015

The thing my coding for sudoku is not working for few inputs... it works fine with all its value initially at 0, but when i place numbers more than 4 at random places it stops responding (it doesn't show any value). My assignment is to get a solved sudoku for these values:

//Sample Input:
{0,2,7,3,8,0,0,1,0},
{0,1,0,0,0,6,7,3,5},
{0,0,0,0,0,0,0,2,9},
{3,0,5,6,9,2,0,8,0},
{0,0,0,0,0,0,0,0,0},
{0,6,0,1,7,4,5,0,3},
{6,4,0,0,0,0,0,0,0},
{9,5,1,8,0,0,0,7,0},
{0,8,0,0,6,5,3,4,0}

My current code

public class Sudoku {
static int userGrid[][]=new int[][]
{{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0}};//[horizontal][vertical]
static int grid[][]=new int[9][9];//the grid that the program experiments on

[Code] .....

View Replies View Related

Exceptions For Multiple Inputs

Oct 29, 2014

I'm writing a program that accepts three doubles from the user, and performs calculations on them. I want to be able to handle input mismatch exceptions on each individually (i.e., if the user enters a double for the first, then a letter for the second, I'd like to be able to keep the value entered for the first, and only require that the user try again with the second, then the third, etc.)... I tried putting each input instance into its own try/catch blocks, but it always goes back to #1 when an invalid input is entered. Right now, I have all three in one try/catch:

Java Code:

package com.itse2317;
import java.util.Scanner;
import java.util.InputMismatchException;
class Triangle
{
public static double side1 = 0.0, side2 = 0.0, side3 = 0.0;

[code]...

View Replies View Related

LWJGL Keyboard Inputs Not Recognized

May 10, 2014

I wanted to create a simple window with the LWJGL and a key input request which closes the window.I also wanted to create the classes in seperated packages, so it's more organized.The window displays but if I press that certain key nothing happens.Here is the Main class:

package bb.main;
import bb.input.Input;
import bb.main.render.SimpleRenderer;
public class Main {
public static void main(String[] args){
SimpleRenderer createWindow = new SimpleRenderer();
Inputinput= new Input();

[code]....

View Replies View Related

Reading Inputs Using Buffered Reader

Oct 13, 2014

I am trying to read the following input (which will be inputted by the user when run) using the BufferedReader approach:

1
*** * * * *** *** *** ***
* * * * * * * * *
* * * *** *** *** *** ***
* * * * * * * * *
*** * * *** *** *** ***

I am reading each line of the input one line at a time and incrementally storing four char positions into an array, so i am able to hold a vertical representation of each column. I.e. column 1 will be stored in array[0].

The problem with my code is that is does not read the last line of the input, it reads all the other inputs before it but just refuses to read the last line and execute the procedure of storing the characters.

Code:

public void defuseBomb(){
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
System.in));
String asciiLine = reader.readLine()+ " ";
int digit = (asciiLine.length())/4;
 
[Code] .....

View Replies View Related

Increasing Counter When User Inputs C / D Or E

Feb 15, 2015

We are writing our own classes and methods. My instructor has provide the code

/*-------------------------------------------------------------------------
import java.util.*;
public class Assignment5 {
public static void main (String[] args) {

[Code].....

I am having trouble with the question counter. I need the counter to increase when c, d or e are entered. I think I need to set up a if or while loop but I'm not sure how to setup the variables. This is what I have for the counter so far.

[public int getNumberOfQuestions(){
numQuestions = 0;
numQuestions ++;
return numQuestions;
}

View Replies View Related

Filling Array With Three Of User Inputs

Aug 9, 2014

I realized that I was not filling the array with anything but now I'm having issues filling it correctly. It's only filling the array with three of the user inputs ....

import java.util.Scanner;
public class DriverSort {
public static void main(String[] args) {
Scanner scan =new Scanner(System.in);
Sorter sorter = new Sorter();
int choice; // variable which says which sorting algorithm to use

[Code] .....

View Replies View Related

Lock Keyboard And Mouse Inputs

Mar 10, 2014

Which methods can be used to lock keyboard and mouse inputs using java??

View Replies View Related

Storing Multiple User Inputs In Array

Feb 28, 2015

I need to generate a league table in Java based on results provided in the shape of user input. I have the 6 teams in an array. I need to ask the user how many wins, draws, losses each team has had.

for (String element : teams) {
System.out.println(
"Please enter the number of wins, draws and losses for " + element);
int[] wins = new int [6];
int[] draws = new int [6];
int[] losses = new int [6];
}

How do I pull 3 separate values from the user and then store each value in a separate element of each array? so if one team wins 3, draws 2 and loses 1 - I need to put 3 into the wins array, 2 into the draws array and 1 into the losses array? I then need to total all this in a table.

View Replies View Related

Anomaly While Using Scanner Class For Taking Inputs

Feb 1, 2015

There is a problem that I am facing while using the Scanner class for taking inputs from the user. Suppose if I need to take an integer and a String input from the user, and I take the integer input first then the place where the user has to input the String skips and the variable shows a "" nothing on printing it. Suppose in this code snippet

import java.util.Scanner;
public class Test
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number");
int n = sc.nextInt();
System.out.println("Enter a word");
String str = sc.nextLine();
System.out.println("Enter integer is " + n);
System.out.println("Entered statement is " + str);
}
}

The output is
Enter a number
13
Enter a word
Enter integer is 13
Entered statement is

I need to know why this happens and how should I avoid it. I've seen that taking the String input first solves the issue but while taking the input in a loop to populate a database the program only lets the user enter the first statement and the following statements are skipped.

View Replies View Related

Return A String That Holds User Inputs

Apr 18, 2015

I'm working on an assignment for my Java Programming class that requires me to work with Multiple Classes.

Overview of the assignment: Create a "Database" that allows a user to input information about a College Class.

My program has three Classes:

The information that must be tracked in the Course Class is:
- Section Number
- Instructor
- Classroom
- Students (an ArrayList of class Student)

The information that must be tracked in the Student Class is:
- Name
- Major
- GPA
- Hours

The Driver class will use the main method to print the user a prompt asking for inputs, then display all of the user's inputs after he/she wished to exit the program.

I'm having no trouble with asking the user for inputs and then checking the validations for the inputs, I'm currently struggling with return a String that houses all of the user's inputs for the variables above. The information must be returned in a method called toString(). Both the Student and Course Class must have a toString() method that returns the information in the class (value of the variables), I must then call upon these methods from the main method of the Driver Class to print them back to the user.

The toString methods within the Student & Course Classes are at the bottom of the code

To Summarize: What I need to do within the toString() methods to return the values the user has inputted for the various variables? Such as.. Should I pass something through the method? Do I need the this keyboard to pass through the variable again? I just fear that I'm currently misunderstanding a very critical part of programming.

My Driver Class

import java.util.Scanner;
public class Driver {
Course courseInputs = new Course();
Student studentInputs = new Student();
public static void main(String[] args) {

[Code] .....

View Replies View Related

Need To Count Strings That How Many Inputs From User Were Numbers

Jan 30, 2014

import java.util.Scanner;
public class CountStringNumbers { // show the number of Strings that were numbers . . ..
public static void main(String []args){
int count = 0;
int countNumbers=0;
Scanner input=new Scanner(System.in);

[code]...

can count the numbers from 0-9 if the user puted but if it is 10 it doesnt count it , and i need to write all the numbers to have that option. . . . Is there an easy way that includes all the numbers? like if(word.equals(number)){<<<???? (numbers) i know htat doesnt work but is there anything similar ?? ??

countNumbers++;
}
System.out.println("Type Something , , , and to end the the termination type STOP");
word=input.nextLine();
count++;
}
System.out.println("You wrote "+count+" lines wich from those lines "+countNumbers+" were numbers and the programe terminated ");
}
}

View Replies View Related

Write A Program Where User Inputs A Month Between 1-12

Sep 21, 2014

I have an assignment where I'm supposed to write a program where the user inputs a month between 1-12 and then the right amount number in every month. I've tweaked the code a bunch of times, but I keep getting this error message:

insert "}" to complete StatementKALENDER_3.java
insert "}" to complete BlockKALENDER_3.java

The code:

import java.util.*;
import java.util.Scanner;
public class KALENDER_3
}
public static void main(String[] args){
Scanner scanner = new Scanner (System.in);
System.out.print("Skriv ett manadsnummer: ");

[code].....

I think I have just forgot to put in a few { } symbols, maybe an open loop?

View Replies View Related

Developing A Program That Inputs Telephone Numbers

Jan 26, 2014

Develop an algorithm for a Java program that takes as input a single letter and displays the corresponding digit on the telephone. The letters and digits on a telephone are grouped this way:

2 = ABC 3 = DEF 4 = GHI 5 = JK 6 = MNO 7 = PQRS 8 = TUV 9 = WXYZ

The screen dialog might look like this: Enter a single letter, and I will tell you what the corresponding digit is on the telephone. R The digit 7 corresponds to the letter R on the telephone.

The program should display a message indicating that there is no matching digit for any non-alphabetic character entered by the user. Also, the application should recognize only uppercase letters. If a user enters a lowercase letter, the program should display an error message. Prompt the user with an informative message for the input value as shown above.

The application should include the input letter as part of the output.

Write the algorithm to solve this problem including steps for prompting the user, getting input from the keyboard, and displaying the results.

Write the Java program that you designed, using your algorithm as a guide. Use your algorithm as comments in the body of the main method.

Use proper indentation, and meaningful identifiers throughout the code.

View Replies View Related

Equivalent Arrays - Comparing 2 User Inputs To Determine If Same

Mar 4, 2015

I have been stuck on this for the past 2 hours, basically we have to compare user input, put user input into an array and compare for equivalency. An example of the program:

Array 1: 1 2 3 4 5 6 7 8
Array 2: 1 2 3 4 5 6 7 8
Array 3: 1 2 3 4 5 6 7 8 9
Array 4: 1 2 3 4 5 6 7 8

Array 1 & 2 are equal
Array 1 & 3 are not equal
Array 1 & 4 are not equal.

This cannot be done by importing Java.util.Array at all!! (my research only find this to compare arrays ) which is why I am having trouble starting off. My code thus far:

import java.util.Scanner;
public class Lab07b {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter Integer 1:");
int a = input.nextInt();

[Code] .....

View Replies View Related

Write A Program For Converting Positive Binary Inputs Into Hex

Sep 29, 2014

I am trying to write a program for converting positive binary inputs into hex.Why am i getting this errors while compiling my binary to hex converter..

Exception in thread "main" java.lang.NumberFormatException: For input string: "148.0"
at java.lang.NumberFormatException.forInputString(Num berFormatException.java:65)
at java.lang.Long.parseLong(Long.java:441)
at BinToHex.convertbintohex(BinToHex.java:24)
at Test.main(Test.java:4)

Here is my BinToHex class

import java.io.*;
public class BinToHex {
double tempDec,fractionpart;
long longofintpart,templongDec;
String inpu ="1001.01";
String hexOutput,intpart,tempDecString,hex = null;

[code]....

View Replies View Related

How To Save Results / Inputs For A Binary Search Algorithm

Apr 24, 2014

Is there a way that I can save a binary search algorithm to a text file or something, so that it will always contain more information? The reason why I ask this is because I have BST like project which is supposed to act the game Twenty Questions, were it asks a person 20 Q's until it guess the answer. However, although my project does not require you to save stuff to a file, I find it rather very useful and cool if I could do that.So for example it would start out something like this:

Think of an animal and I will guess it.
Does it have legs? YES
Is it a cat? YES
I win! Continue? YES

Think of an animal and I will guess it.
Does it have legs? NO
Is it a snake? YES
I win! Continue? YES

Think of an animal and I will guess it.
Does it have legs? NO
Is it a snake? NO
I give up. What is it? EARTHWORM
Please type a question whose answer is yes for an earthworm and no for a snake.
DOES IT LIVE UNDERGROUND?
Continue? YES

Think of an animal and I will guess it.
Does it have legs? NO
Does it live underground? NO
Is it a snake? NO
I give up. What is it? FISH
Please type a question whose answer is yes for an earthworm and no for a snake.
DOES IT LIVE IN WATER?
Continue? NO
Good-bye.

However, if the user exits the program then everything will be lost and go to waste. So once again, is there a way that I can save all of these inputs to a file or something and then read it in again?

View Replies View Related

Take Multiple Inputs In Single Line Separated By Space

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

Display Largest And Smallest Numbers In A Series Of 10 Inputs

Apr 15, 2014

I have to get the user to enter in 10 numbers and with those 10 numbers I have to find the total, average, smallest, largest numbers in the set the user inputs. I have the total and average already figured out but how would you go about trying to find the largest and smallest numbers within this set of code.

import java.util.*;
public class testhw7
{
public static void main (String [] args) {
Scannernumberin = new Scanner (System.in);
doublevalue[];
doubletotal;

[Code]...

View Replies View Related

Java Code - Multiple Execution Of Jar File With Different Inputs

Jan 4, 2014

I would like to ask you how can i execute the next code without errors.

I am trying to execute a jar (myFile.jar) file multiple times with different inputs from another jar file. More simple i have game with many players and i create a Round Robin scheduling for the tournament, i need to execute all the mach's of a round together.

When i run the next code it execute on the first game with the first players multiple times.

Java Code:

public class RunJARFile {
//10 player
//5 game per round
public static void main(String[] args) throws IOException {
for (int Tour = 0; Tour < 9 ; Tour++) {
for (int Game = 0; Game < 5; Game++) {

[Code] ....

View Replies View Related

Adding Inputs To Table With Columns And Perform Calculations Later

Nov 22, 2014

I am trying to put together a small application in my spare time. Nothing major, but one thing I want it to do is accept a few inputs, and take those and add them to a table with columns for use later (printing, calculations, etc). I was originally looking at something like Jtable, but that looks just like an excel spreadsheet done Java, so not what I'm looking for.

I'm looking for something that's read-only, where I can insert data from input fields, and then perform calculations with the column data later.

View Replies View Related







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