user-input

Java Arraylist to store user input

你说的曾经没有我的故事 提交于 2019-11-28 14:42:16
Hi I am new to arraylists and java and I was wondering if someone could help me or give me pointers on how to create a program that allows the user to repeatedly enter directory entries from the keyboard and store them in an arraylist. enter name: enter telephone number: and then ask if the user wants to enter another one enter another: Y/N thanks You can still use two ArrayLists, or make a class with name and phone attributes and then make one ArrayList of objects of that class. First approach shown here. import java.util.ArrayList; import java.util.Scanner; public class AAA { public static

User input to repeat program in Java

守給你的承諾、 提交于 2019-11-28 14:31:55
I am writing a simple guessing game program where the user will input a number to try and guess a randomly generated number. If they get the number right I want to give them the option to play again. Here is my code: public class GuessingGame { private Random num = new Random(); private int answer = num.nextInt(10); private int guess; private String playAgain; public void inputGuess(){ System.out.println("Enter a number between 1 and 10 as your first guess: "); Scanner input = new Scanner(System.in); guess = input.nextInt(); do{ if (guess < 1 || guess > 10){ System.out.println("That is not a

How to get input without pressing enter every time?

人走茶凉 提交于 2019-11-28 12:42:17
I made a simple game(well not really a game yet) in which the player can move in a room 4x20 characters in size. It runs in console. But in my game loop I want to be able to move around in the room without pressing enter every time I want to move. The player should be able to press w/a/s/d and have the screen update instantly, but I don't know how to do that. public class Main{ public static void main(String[] args){ MovementLoop(); } public static void MovementLoop(){ Scanner input = new Scanner(System.in); int pos=10, linepos=2; String keypressed; boolean playing = true; while(playing ==

Detect Keyboard Input Matlab

孤人 提交于 2019-11-28 12:08:08
I have a simple question, although it's harder than it seems; I couldn't find the answer on the interwebs :O I'm writing a script in Matlab. What I want to do is the following: When I press the esc key, I want a helpdialogue to pop up, so my script pauses. (So when I press esc, I want to stop the whole script to run so that the car (which im writing the script for) stops driving) How do I do this? How can I say to Matlab: When I press esc, do this... Thanks for your time guys! EDIT: It's no option to implement something which awaits the keypress. Im writing a script for a driving car. It just

Converting user-entered search query to where clause for use in SQL Server full-text search

房东的猫 提交于 2019-11-28 12:02:51
What's the best way to convert search terms entered by a user, into a query that can be used in a where clause for full-text searching to query a table and get back relevant results? For example, the following query entered by the user: +"e-mail" +attachment -"word document" -"e-learning" Should translate into something like: SELECT * FROM MyTable WHERE (CONTAINS(*, '"e-mail"')) AND (CONTAINS(*, '"attachment"')) AND (NOT CONTAINS(*, '"word document"')) AND (NOT CONTAINS(*, '"e-learning"')) I'm using a query parser class at the moment, which parses the query entered by users into tokens using a

Efficient input in OCaml

天大地大妈咪最大 提交于 2019-11-28 11:34:17
Suppose I am writing an OCaml program and my input will be a large stream of integers separated by spaces i.e. let string = input_line stdin;; will return a string which looks like e.g. "2 4 34 765 5 ..." Now, the program itself will take a further two values i and j which specify a small subsequence of this input on which the main procedure will take place (let's say that the main procedure is the find the maximum of this sublist). In other words, the whole stream will be inputted into the program but the program will only end up acting on a small subset of the input. My question is: what is

Check if the input is a number or string in C++

心已入冬 提交于 2019-11-28 11:25:16
I wrote the following code to check whether the input(answer3) is a number or string, if it is not a number it should return "Enter Numbers Only" but it returns the same even for numbers. Please suggest me a solution. #include <iostream> #include <string> #include <typeinfo> #include <stdio.h> #include <stdlib.h> #include <ctype.h> using namespace std; int main () { string ques1= "Client's Name :"; string ques2 = "Client's Address :"; string ques3 = "Mobile Number :"; char answer1 [80]; string answer2; int answer3; cout<<ques1<<endl; cin>>answer1; cout<<ques2<<endl; cin>>answer2; cout<<ques3<

JUnit test for console input and output

牧云@^-^@ 提交于 2019-11-28 11:16:08
问题 I have only one method main. How to check System.out.println() and replace Scanner to input values automatically using JUnit? P.S. Please, provide some solutions... public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int[] arr = new int[4]; for (int i = 0; i < arr.length; i++) { arr[i] = scanner.nextInt(); } for (int i = 0; i < arr.length; i++) { int res = 0; int k = 0; int num = arr[i]; /*.....*/ System.out.println(num); } } 回答1: Ideally, extract the awkward

How to use int16_t or int32_t with functions like scanf [duplicate]

邮差的信 提交于 2019-11-28 10:51:43
This question already has an answer here: printf format specifiers for uint32_t and size_t 4 answers The way that I understand int16_t or int32_t in C is that they are typedefed to be 16 and 32 bit numbers respectively on your computer. I believe you would use these when you need to guarentee a number is 16 or 32 bits because different systems do not always represent an int as 32 bits or a short as 16 bits (Is this assumption correct? I find mixed answers when I look online.). My question is how would I use a function like scanf to get input from a user with a int16_t or a int32_t or any of

Android link navigation and box input on internet

隐身守侯 提交于 2019-11-28 10:46:32
问题 How can I get android to "navigate" through links on website? Say the first activity in my app allows the user to input their username and password, which would then be stored into Strings. Then the app would "enter" the strings into the username and password boxes and "click" the login button on the website. This "filling" and "clicking" would be done in the background, while the user sees a loading screen. This is the basic idea. So how would I get the app to "fill" in the username and