Saving input to variables? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
0

Saving input to variables?

I'm trying to create a simple program that asks for input and outputs somthing based on it... any one know how I could?

4th Jan 2017, 12:50 AM
Tyler
2 ответов
+ 1
import java.util.*; public class test{ public static void main(String[] args){ Scanner input = new Scanner(System.in); System.out.print("Input: "); int a = input.nextInt(); // accepting input as integer System.out.println("Output: " + a); // print output } } However, if u want to accept input as double or String or char, u can use the following: double a = input.nextDouble(); String a = input.nextLine(); char a = input.next().charAt(0);
19th Jan 2017, 4:00 AM
lowshuen
0
Thanks!
4th Jan 2017, 3:38 AM
Tyler