you have used br.readLine()
4 times and scan.nextInt();
1 time your code will ask to input value 5 times, instead create object of Scanner
and read int
or String
according to your requirement.
infinite execution while taking input through console
Domanda
I am not a total newbie but I got caught in a strange problem while taking input through console in java! Here is my code:
package com.test;
import java.io.*;
import java.util.Scanner;
public class EvenSum {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int a1 = Integer.parseInt(br.readLine());
// tried through scanner class even
Scanner scan = new Scanner(System.in);
int a3 = scan.nextInt();
String input = br.readLine();
int a2 = Integer.parseInt(br.readLine());
DataInputStream in = new DataInputStream(System.in);
int a = in.readInt();
scan.close();
}
}
I have tried doing it by all the four ways separately but the execution of the code simply doesn't end it keeps going on and on. Did I break something? Thanks in advance!
Soluzione
Altri suggerimenti
Try this:
Scanner input = new Scanner(System.in);
int num = input.nextInt();
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow