|  | 
|  | 
| вернуться в форум | Why Runtime error Послано Vlad  10 авг 2019 16:04import java.util.Scanner;
 public class Main {
 
 private static void checking(double a){
 if(Math.sqrt(a)%1==0){
 System.out.printf("%.0f",Math.sqrt(a));
 }else{
 System.out.printf("%.4f",Math.sqrt(a));
 }
 }
 
 public static void main(String[] args) {
 Scanner scanner = new Scanner(System.in);
 System.out.print("Сколько чисел хотите ввести: ");
 int a = scanner.nextInt();
 
 double[] b = new double[a];
 
 for (int i = 0; i < b.length; i++) {
 System.out.print("Число " + (i+1) + ": ");
 b[i] = scanner.nextDouble();
 }
 
 for(double c : b){
 System.out.print("Корень " + c + " = ");
 checking(c);
 System.out.println();
 }
 }
 }
Re: Why Runtime error I'm not sure what's causing the runtime error, but I tried your code on an online compiler and this was the error message I got:
 Exception in thread "main" java.util.NoSuchElementException
 at java.base/java.util.Scanner.throwFor(Scanner.java:937)
 at java.base/java.util.Scanner.next(Scanner.java:1594)
 at java.base/java.util.Scanner.nextDouble(Scanner.java:2564)
 at Main.main(Main.java:22)
 | 
 | 
|