Type Here to Get Search Results !

Input / Output in Java using Scanner.

0

       Input / Output in Java using Scanner.


Most popular way to read input in java is by using Scanner

For example:

Scanner scanner = new Scanner(System.in);
int myInt = scanner.nextInt();
System.out.println("myInt is: " myInt);


The code above creates a Scanner object named scanner and uses it to read an integer. It prints output using System.out.println(MyInt). 

So, if our input is:

5

Our code will print  :-  myInt is: 5

User Task :-

In this challenge, you must read 3 integers and then print them. Each integer must be printed on a new line.

Input Format
There are 3 lines of input, and each line contains a single integer.

Sample Input :-

42
100
125

Sample Output :- 

42
100
125

Solution :- 

import java.io.*;
import java.util.*;
public class Main {
    public static void main(String args[]) {
        // your code here
        Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
System.out.println(a);
System.out.println(b);
System.out.println(c);

    }
}



Common Mistakes :-

Do not print anything extra. Just print the numbers only in separate lines.
Make sure you give 3 integers in input box below before running your code. If you do not give integers as input, you will face an error.

Post a Comment

0 Comments