pages:
  • 1
MMBs of IAUT SAYS
/* * Why this program has runtime error ???!!!!!
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner inp = new Scanner(System.in);
String input;
int [] c = new int [1];
int i=1;     
boolean flag = true;
input=inp.nextLine();
String [] A = input.split(" ");
c[0]=Integer.parseInt(A[0])+Integer.parseInt(A[1]);
System.out.println(c[0]);
while (flag){
  input=inp.nextLine();  
  A = input.split(" ");
  c=Arrays.copyOf(c, c.length+1);
  c[i]=Integer.parseInt(A[0])+Integer.parseInt(A[1]);
  System.out.println(c[i]);
  i++;
}
}
}
AMiR SAYS

I highly suggest you run your code in command line instead of IDE, and redirect stdin and stdout to files. Like this:

javac Main.java
java Main < input.txt > outout.txt

This way you can see if there is a runtime error in reading the input.

Exception in thread "main" java.util.NoSuchElementException: No line found
at java.util.Scanner.nextLine(Scanner.java:1533)
at Main.main(Main.java:14)

You should not read line if there is not one.

abol SAYS

you must change value of flag in while loop if somthing then flag = false

MMBs of IAUT SAYS

abol said:

you must change value of flag in while loop if somthing then flag = false

when we should change the flag to false ?