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?
2 Respostas
+ 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);
0
Thanks!