prendere valore da tastiera java 1

prendere valore da tastiera java

  import java.util.Scanner;

public class Main{
    public static void main(String args[]){

    Scanner scan= new Scanner(;

    //For string

    String text= scan.nextLine();


    //for int

    int num= scan.nextInt();

  /*Is better to create another instance of Scanner if you have to use both nextline 
  	and nextInt because they can conflict each other

Here is what the above code is Doing:
1. We are creating a new instance of Scanner class.
2. We are using the nextLine() method to read a line of text.
3. We are using the nextInt() method to read an integer.

Similar Posts