user-input

Recognize arrow keys in Java Scanner or Console application

送分小仙女□ 提交于 2021-02-18 02:48:38
问题 I am writing a Java application that uses both Scanner and Console to get input from the user. I would like to add command history support so that the user can use the ARROW KEYS to search previous inputs (similar to a terminal). Is there a way to do this? Right now, when I use either the Scanner or the Console , I get weird symbols like ^[[A when pressing the arrow keys. I have read about KeyListener and KeyEvent , but my application does not use a GUI. Thanks! 回答1: Good question - +1'd. On

Recognize arrow keys in Java Scanner or Console application

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-18 02:45:08
问题 I am writing a Java application that uses both Scanner and Console to get input from the user. I would like to add command history support so that the user can use the ARROW KEYS to search previous inputs (similar to a terminal). Is there a way to do this? Right now, when I use either the Scanner or the Console , I get weird symbols like ^[[A when pressing the arrow keys. I have read about KeyListener and KeyEvent , but my application does not use a GUI. Thanks! 回答1: Good question - +1'd. On

Write user input to file python

烈酒焚心 提交于 2021-02-17 07:02:23
问题 I can't figure out how to write the user input to an existing file. The file already contains a series of letters and is called corpus.txt . I want to take the user input and add it to the file , save and close the loop. This is the code I have : if user_input == "q": def write_corpus_to_file(mycorpus,myfile): fd = open(myfile,"w") input = raw_input("user input") fd.write(input) print "Writing corpus to file: ", myfile print "Goodbye" break Any suggestions? The user info code is : def segment

How to get elements of an array that is not null

两盒软妹~` 提交于 2021-02-17 05:16:07
问题 I am doing gift (String-type) storage, using arrays, with the maximum 500 million. I want to get the number of used elements in an array like how many gifts are currently in stock, (I.E. I stored 253538 gifts, but I don't know that. Is there a command in Java that can know that there is only 253538 Slots in the array that contain an element). But I don't know how to. Here's the snippet of code I want to use: static String[] Gifts = new String[500000000]; static int i = 0; String command, Gift

Continuos loop with user input condition in python?

耗尽温柔 提交于 2021-02-11 13:11:22
问题 I just learn my first python and try to make a continuous loop that has a user input condition. #Make the calculating func def data_cal(): pennies = int(input("What's your pennies?")) dollars = pennies // 100 cents = pennies % 100 print("You have $", dollars, "and", cents, "cents") data_cal() #User input for answer repeat = input("Do you want to try again?") answer = ['yes','YES','Yes','y','Y'] #Loop for answer while repeat in answer data_cal() else: print("Bye then") I was thinking if I can

Continuos loop with user input condition in python?

旧城冷巷雨未停 提交于 2021-02-11 13:08:41
问题 I just learn my first python and try to make a continuous loop that has a user input condition. #Make the calculating func def data_cal(): pennies = int(input("What's your pennies?")) dollars = pennies // 100 cents = pennies % 100 print("You have $", dollars, "and", cents, "cents") data_cal() #User input for answer repeat = input("Do you want to try again?") answer = ['yes','YES','Yes','y','Y'] #Loop for answer while repeat in answer data_cal() else: print("Bye then") I was thinking if I can

Continuos loop with user input condition in python?

痴心易碎 提交于 2021-02-11 13:04:57
问题 I just learn my first python and try to make a continuous loop that has a user input condition. #Make the calculating func def data_cal(): pennies = int(input("What's your pennies?")) dollars = pennies // 100 cents = pennies % 100 print("You have $", dollars, "and", cents, "cents") data_cal() #User input for answer repeat = input("Do you want to try again?") answer = ['yes','YES','Yes','y','Y'] #Loop for answer while repeat in answer data_cal() else: print("Bye then") I was thinking if I can

User prompts with multithreading

不羁的心 提交于 2021-02-11 12:17:05
问题 I have a couple threads running at once, doing things in the "background", but then the program reaches a point where it needs user input for all the threads to continue. Below is what I have written, and it works, but it seems inefficient and I'm not sure how else to do it as this is my first experience with multi-threading. global userPromptFlag = 1 # first thread to reach this condition prompts the user for info if (userPromptFlag == 1): userPromptFlag = 0 self.userPrompts() else: # other

opening a file based on user input c++

做~自己de王妃 提交于 2021-02-11 08:01:54
问题 I am trying to make a program that would open a file based on the users input. Here`s my code: #include <iostream> #include <fstream> #include <string> using namespace std; int main() { string filename; ifstream fileC; cout<<"which file do you want to open?"; cin>>filename; fileC.open(filename); fileC<<"lalala"; fileC.close; return 0; } But when I compile it, it gives me this error: [Error] no match for 'operator<<' (operand types are 'std::ifstream {aka std::basic_ifstream<char>}' and 'const

opening a file based on user input c++

让人想犯罪 __ 提交于 2021-02-11 08:01:31
问题 I am trying to make a program that would open a file based on the users input. Here`s my code: #include <iostream> #include <fstream> #include <string> using namespace std; int main() { string filename; ifstream fileC; cout<<"which file do you want to open?"; cin>>filename; fileC.open(filename); fileC<<"lalala"; fileC.close; return 0; } But when I compile it, it gives me this error: [Error] no match for 'operator<<' (operand types are 'std::ifstream {aka std::basic_ifstream<char>}' and 'const