user-input

Is there any way I can use a Scanner object in a different class?

风流意气都作罢 提交于 2019-12-12 10:22:33
问题 So I have a simple Scanner object: Scanner scan = new Scanner (System.in); I am trying to use this Scanner object inside a method that I have declared in a different class. Is there anyway this can be done? I have also tried using: public static final Scanner scan = new Scanner(System.in); but this didn't really help 回答1: public static final Scanner scan = new Scanner(System.in); As you have declared Scanner instance as public and static . So you access it using the Class reference. Code in

how to catch blank input with scanner class in java

前提是你 提交于 2019-12-12 09:43:45
问题 I am using the scanner class to capture user input from the command line (strings only), as an alternative to my previous question. The following seems to work fine, except the blank lines are not caught as they should by the second conditional. For example when I press enter, this should be captured as a blank line and the second conditional should be true. However a new blank line is displayed on the console everytime, with the entire console "scrolling" upward if I keep hitting enter,

Force input to be positive numbers only with error handling in C

[亡魂溺海] 提交于 2019-12-12 07:07:39
问题 I have a trivial question to ask. My program should take postive integers only. If there is anything illegal, the user should be prompted to input a number again. The code I have for now is: #include<stdio.h> int main(){ int reads; int num=0; char a; while(num<=0){ printf("Please Enter positive integer: "); while(((reads = scanf("%d%c", &num, &a)) != 2 && reads != EOF) || a != '\n' ){ do { printf("Please Enter positive integer: "); reads = scanf("%c", &a); }while(reads != EOF && a != '\n'); }

Eclipse CDT Mars: Input from a file [closed]

爷,独闯天下 提交于 2019-12-12 06:33:43
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . I have recently installed Eclipse CDT Mars release for running C Programs. I am facing problems with taking input from a file. So, I have a program that looks like this: int main(void) { //Declarations int number_of_segments; int k_constraint; segment_node *ptr_to_segment_array, *ptr_to_segment_sorted_array; int

How to write user input to a text file using fputs in C++

半腔热情 提交于 2019-12-12 05:41:35
问题 I am not the best programmer with c++ but I am trying to learn. I am trying to take user input and write it into a text file (without overwriting the old one) but I can't figure out where to plugin the variable (int). Here is my code so far... int main() { int i; cout << "Please enter something: "; cin >> i; FILE * pFile; pFile = fopen ("C:\\users\\grant\\desktop\\test.txt","a"); if (pFile!=NULL) fputs ("C++ Rocks!",pFile); fclose (pFile); getch(); return 0; } Also, if there is a more

Simulate User Input in 3rd Party Application

让人想犯罪 __ 提交于 2019-12-12 05:15:14
问题 Not sure where to start with this one ... I'm thinking about creating a small little application to automate some repetitive text entry. I would like to be able to define snippets of text, and inject them into other applications when I want. What would be the best way to approach this problem? I have stumbled across UI Automation, as well as SendKeys. Any suggestions? I don't mind if I have to "point out" the input controls for the application (like how Mac's native screenshot tool asks you

Show WinFrm from C# console application and wait to close

亡梦爱人 提交于 2019-12-12 04:44:47
问题 I am trying to show a WinForm (inputbox) from a console application in C# and wait until the user closes the form. It is important for me to have the inputbox ontop and active when it opens. ShowDialog() is not working in my case as in some cases it does not appears as an active form. So I'd like to change my code and use Show(). This way I can manually make find out if the form is active or not and if not activate it myself. With ShowDialog(). my code stops and I can not do anything until

input from user using for loop and prompt dialogue box shows different behaviour

时光毁灭记忆、已成空白 提交于 2019-12-12 04:26:12
问题 i used the code below to get user input in android app. it runs fine but what i found after several attempts is that. the method below is called from a for loop to get different values. The code takes input in reverse order i.e it has to take value for x and then y. while on the app i am asked to enter value of y and then x. it doesnot wait for the user input it shows the dialogue box but keeps on running the whole program. as when i enter any value doesnt make any changes as it has to do.

How to stop a while loop to get input from user using Tkinter?

a 夏天 提交于 2019-12-12 03:46:15
问题 it is incredible how the knowledge of something so basic can be buried in a so hard to find place. I have spent close to a month googling for an answer--watching videos, reading documents, books, etc--of how to stop a while loop to get input from an user using Tkinter. My code below is looping twice and leaving the loop before I am able to provide an input!!! Anyway, theory is appreciated, but a sample code will be of greater help. Thank you very, very much indeed. # Python 3.5.1 from tkinter

grading a students test based on user input answers [closed]

流过昼夜 提交于 2019-12-12 03:36:17
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 6 years ago . I have to Declare/Initialize an array to hold the correct answers to a 12 question multiple choice quiz whose answers are: 'B', 'D', 'A', 'A', 'C', 'A',