Answers for "Write a program in Java, using the Scanner methods, to read and display the following details"

10

how to use scanners in java

import java.util.Scanner;

Public class Scanner {
	Public static void main(String[] args) {
    	// Scanner *scanner name here* = new Scanner(System.in);
      	Scanner scan = new Scanner(System.in);
      	System.out.println("Type anything and the scanner will take that input and print it");
      	String next = scan.next();
      	System.out.println(next);
    } 
}
Posted by: Guest on August-18-2020
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
1

java scanner functions

import java.util.Scanner;
public class scanners{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in); 
    // Reading int
    System.out.print("Enter your age");
    int age = scan.nextInt();
    // Reading double
    System.out.print("Enter your salary");
    double salary = scan.nextDouble();
    // Reading float
    System.out.print("Enter employees average salary");
    float average = scan.nextFloat();
    // Reading Single Character
    System.out.print("Enter any character from a to z");
    char charcter = scan.next().charAt(0);
    // Reading string
    System.out.print("Enter your full name");
    String fullname = scan.next();
    // Reading long
    System.out.print("enter a long number");
    long number = scan.nextLong();
  }
}
Posted by: Guest on June-17-2021

Code answers related to "Write a program in Java, using the Scanner methods, to read and display the following details"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language