Answers for "is scanner input or output"

2

Java scanner example

import java.util.Scanner;
public class AddTwoNumbers2 {

    public static void main(String[] args) {
        
        int num1, num2, sum;
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter First Number: ");
        num1 = sc.nextInt();
        
        System.out.println("Enter Second Number: ");
        num2 = sc.nextInt();
        
        sc.close();
        sum = num1 + num2;
        System.out.println("Sum of these numbers: "+sum);
    }
}

Output:
Posted by: Guest on June-08-2020
0

User input (scanner)

String line = scanner.nextLine();
int age = Integer.parseInt(line); // Exception-t
Posted by: Guest on April-25-2021
0

User input (scanner)

int age = scanner.nextInt();
scanner.nextLine(); //Ez fogja az ottmaradt sorvége jelet beolvasni
        
String name = scanner.nextLine();
Posted by: Guest on April-25-2021

Code answers related to "is scanner input or output"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language