Reading Values From The Keyboard?
Aug 21, 2014
why we are not able to read second string in this program.
String s1,s2,s3;
String decider;
Scanner sc = new Scanner(System.in);
[Code].....
Note: If I uncomment line num 9 it works fine
View Replies
ADVERTISEMENT
Feb 20, 2014
Write a program that extracts words from a file. For the purposes of this program, a word is defined as a series of adjacent letters. Only print words that are at least four and no more than 12 letters long. Print each word on a different line.
The program should read the name of the file from the keyboard.
************************************************** ************************************************** **************
I need to get the filename from the user for this particular program. Usually I would have the name of the file prewritten into the source code like this....
Scanner input = new Scanner(new File("gettsy_burg.txt");
I tried different ways but I just can't seem to figure it out.... I guess what I'm really asking is how to rearrange Scanner input = new Scanner(new File("gettsy_burg.txt"); since I want the user to input the filename instead of the filename being prewritten by the programmer(me).
This is what I have so far to let the user for input....
Scanner keys = new Scanner(System.in);
System.out.println("Enter the filename: ");
String fileName = keys.nextLine();
keys = new Scanner(new File(fileName));
View Replies
View Related
Feb 20, 2014
Write a program that extracts words from a file. For the purposes of this program, a word is defined as a series of adjacent letters. Only print words that are at least four and no more than 12 letters long. Print each word on a different line.
The program should read the name of the file from the keyboard.
************************************************** ************************************************** **************
I need to get the filename from the user for this particular program. Usually I would have the name of the file prewritten into the source code like this....
Scanner input = new Scanner(new File("gettsy_burg.txt");
I tried different ways but I just can't seem to figure it out....
View Replies
View Related
Aug 9, 2014
i tried to run simple program od adding two number by using scanner class but there is run time error here it is code file and error.
View Replies
View Related
Apr 13, 2014
So here is my code:
while (key != 3) {
if (key == 2) {
System.out.println("Input from a file");
// System.out.print("Enter file name: ");
// String str = expression.nextLine();
int i = 0;
File file = new File(
[code]....
What I need to happen is the file gets read in, the file is in the form:
a * ( b + c ) / 2 + ( 8 * b )
a = 5
b = 10
c = 20
( x + y ) * z
x = 13
y = 21
z = 3
And so on. My code is supposed to start at the beginning and have output like:
Infix: a * b ( b + c ) / 2 + ( 8 * b )
variable values:
a = 5
b = 10
c = 20
**It then needs to store the variable names along with their values in a hash table**
postfix: a b c + * 2 / 8 b * +
value: 155
And it continues reading the file in the same fashion.
My issue is I am not properly extracting the variables and their values from the file. I have the variables in an array list actually, so I have those, but don't know how to efficiently navigate to the values, then store the character and value in a hash table, while protecting against possible blank lines within the file. Thus just calling nextLine()s and next()s wouldn't work to get to values because they would lead to an error.
View Replies
View Related
Apr 8, 2014
I've been trying to learn how to read in file input and have a question about this piece of code:
Java Code:
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;
public class readFile {
public static void main(String args[]) throws FileNotFoundException{
File file = new File("file.txt");
int sum[]=new int[5];
int i=0;
[Code] .....
"file.txt" holds the following information:
1
2
88
42
56
89
But my output looks like:
2
42
89
if I take out sum[i]=input.nextInt(); it will display all values in the file.
View Replies
View Related
Mar 8, 2014
My code's not working and I don't know why. I'm trying to read numerical values from a file and saving all instances where a letter is entered instead of a number to a string to be referenced as an error at a later point on in the code. However, there's an error and like I've stated before, I don't know what caused it.
public static void validateData() throws IOException{
File myfile = new File("gradeInput.txt");
Scanner inputFile = new Scanner(myfile);
for (int i=0; i<33; i++){
if(inputFile.hasNextDouble()){
double d = inputFile.nextDouble();
if (d<0||d>99999){
[Code] ....
This is the error that returns.
Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:838)
at java.util.Scanner.next(Scanner.java:1347)
at Paniagua_Grading.validateData(Paniagua_Grading.java:29)
at Paniagua_Grading.main(Paniagua_Grading.java:6)
View Replies
View Related
Sep 13, 2014
//compiler error I'm receiving
J:CS3Student Folder Review Lab #2APlusImage.java:41: error: cannot find symbol
xcor.add(read.nexInt());
[Code].....
View Replies
View Related
Jul 14, 2014
I am writing a code that tries to figure out the users password by going through every possible key (brute force). Although I think its going to work, it looks EXTREMELY inefficient to me, since its just a huge switch statement for each character -- 94 total, including the shift values. Is there a built in method in the JAVA API that goes through every key or something?
Here is my code for that segment:
public char[] HackingPassword(){
char[] passChars = this.password.toCharArray();//convert the password to char[]
char[] hacking = new char[passChars.length];//make the hacking variable same size as users password
int nextCharValue = 0;//this is used to cycle through the keyboard
//check each letter of hacking to match with password
for(int i = 0; i < passChars.length; i++){
[Code] .....
View Replies
View Related
Sep 4, 2014
I created a scanner object but it's not asking for any input. when I create a new scanner and then tell it to print it it just prints a bunch of weirdness when AFIK it should be asking me to type something and then it should repeat what i entered.
View Replies
View Related
Oct 8, 2014
I wanted to make a small program to move a small rectangle by pressing the WASD keys. The program works, except that when I hold a key to move the rectangle, after a second, auto-repeat starts up, and the rectangle motion accelerates. I want to prevent automatic repeat to activate, so that the rectangle moves at a constant speed when I hold a key and stops when I released. Here is the ButtonMotion classe :
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.KeyStroke;
[code]....
View Replies
View Related
Jun 21, 2014
I want to enter the triangle data in the method and every time I try to compile the program I get the error message--cannot find symbol.
import java.io.*;
import java.util.*;
public class trianglemethod {
public static void main(String [] args) {
Scanner kbreader = new Scanner (System.in);
[Code] .....
View Replies
View Related
Apr 8, 2014
I am testing to get a double value from keyboard input as below?
import java.util.Scanner;
public class EchoLine{
public static void main(String[] args){
double amount;
Scanner myScanner=new Scanner(System.in);
amount=myScanner.nextDouble();
System.out.println(amount);
}
}
I type 5.95 in Console View of Eclipse but as a result I get an error on line 9.
View Replies
View Related
Mar 26, 2015
I want to use backspace button in my keyboard how can i create this button in my code ???
View Replies
View Related
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
Jan 29, 2015
so i'm working in a chat program and i'm trying to make it so that you are able to open another tab yet still be able to chat.
right now the client that the user download uses the keyadapter to get the keyboard input, but whenever the user un-focus the chat window, the keyadapter no longer gets the keyboard input.so is there another way i can get the keyboard input? so it doesn't matter what window you are focused on, you get the keyboard input either way?
View Replies
View Related
Jul 4, 2014
package com.vesron.primes;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
[code]....
The parameter for the starting y is "fy" (Half of the screen). When I use the keys "z" and "x" it translates one pixel at a time left and right. That is good, but when I use the keys "a" and "s" it will double each time (good), but the starting y will drop significantly (bad). I tried manipulating the "x" and "fy" variables, but to no avail.
View Replies
View Related
Mar 10, 2014
Which methods can be used to lock keyboard and mouse inputs using java??
View Replies
View Related
May 21, 2014
How to save a date entered by the keyboard?
View Replies
View Related
Oct 24, 2014
My question is to evaluate a Postfix notation entered from keyboard. I have no errors in my code but it prints only :
Exception in thread "main"
java.util.NoSuchElementException
at ArrayStack.pop(PostFixEvaluation.java:72)
at PostFixEvaluation.evaluatePostfix(PostFixEvaluatio n.java:107)
at PostFixEvaluation.main(PostFixEvaluation.java:140)
I tried many values but it prints the same exception all the time.
Here is my code:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.NoSuchElementException;
interface Stack<E> {
[Code] ....
View Replies
View Related
Sep 14, 2014
I am trying to create this program I am pretty sure it is easy but I am making it difficult lol, it keeps giving me a error, it is saying cannot find symbol - variable keyboard, I don't think I have keyboard as a variable but I may be wrong.
double distancel = keyboard.nextdouble(); that is the specific line ....
import javax.swing.JOptionPane;
import java.io.File;
import java.util.Scanner;
//import java.util.totalInches;
//instance variables
public class Map{
public static void main(String[] args){
[Code] ....
View Replies
View Related
Sep 12, 2014
import java.util.Scanner;
public class main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int number;
System.out.println("Input a number");
[code]....
What i want to do is that if the number is greater than 50 to count until 100. else if the number is less than fifty to count for example from 36 to zero.
View Replies
View Related
May 7, 2015
a code that will add 1 to a variable and store it anytime key "p" is pressed on the keyboardKeep in mind
Here's what i have....
import java.util.Scanner;
public class Main {
public static void main(String args[]){
Scanner kin = new Scanner (System.in);
int pa, ma;
[Code]...
View Replies
View Related
Dec 5, 2014
I'm having issues with providing focus to keyboard buttons when a JInternalFrame with keyboard buttons is called in my program. So for example when the program is started the attachment called signinscn.png is called.
This screen is a JDesktopPane which calls JPanel for its components.
From here a JInternalFrame containing the buttons ESC and F1 to F4 as seen in the attachment called signinscn.png is called.
I would like the buttons in my JInternalFrame to have focus such that when a user engages the equivalent keyboard button i.e. ESC or F1 to F4 WITHOUT clicking on the JInternalFrame the respective button's action listener kicks in. At the moment only after the user clicks on the JInternalFrame do the equivalent keyboard buttons respond.
Here's the constructor of my JInternalFrame and you can see how I handle the ESC keyboard button in the constructor of the JInternalFrame (but as I mentioned only after the user has engaged the JInternalFrame):
//!<
public AdminHomeJIFrame() {
super(null, false, // Resizable
false, // Closable
false, // Maximizable
false); // Iconifiable
BasicInternalFrameTitlePane titlePane =
(BasicInternalFrameTitlePane)((BasicInternalFrameUI)this.getUI()).getNorthPane();
[Code] ....
View Replies
View Related
Aug 16, 2014
i want to make a piece of software that enables me to Press a key on my keyboard and then it will play a Sound. But i Want to be able to do it when i'm playing.Can code The Sound an Keys
View Replies
View Related
Apr 8, 2014
Basically i have a question ask me to write a program that read integer from keyboard until a negative number is entered, and then print out the max and min out of the number i have entered.
This is what i have done already which works, but i need to ignore the negative number when print out max and min...which i dont know how to do so. when i compile this program now it will always give me the negative number i enter at the end as minimum. which i need to ignore
Also if negative number is entered at once the program should print a error message say max and min are undefined.
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int large = Integer.MIN_VALUE;
int small = Integer.MAX_VALUE;
while(true) {
System.out.print("Enter a integer: ");
int n = in.nextInt();
[Code] ....
View Replies
View Related