import java.io.*; public class chisla { public static void main ( String [ ] args) { BufferedReader a=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Веди`enter code here`те число а"); BufferedReader x=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Ведите число x"); BufferedReader e=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Ведите число E"); String a1=a.readLine(); String x1=a.readLine(); String e1=a.readLine(); double [ ] mas; for(int i=1;i<10;i++) { mas[0]=a1; mas[i]=1/2*(mas[i-1]-(x1/mas[i-1])); } } } 

initial task

  • Sorry to upset you, but the code above is a rare nonsense :( It is not even clear what you were trying to do. It is not clear what a1, x1 and e1 are and what unthinkable things you try to do in a loop with an array that is always empty. - cy6erGn0m
  • And, now I understood what was required ... your link to the task was not visible. It is obvious that you have not yet understood the topic at all. You should think hard about it. - cy6erGn0m

3 answers 3

However, despite the comment, the answer to the original question

 import java.io.*; public class chisla { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); try { System.out.println("Введите число а"); double a = Double.parseDouble(reader.readLine().trim()); System.out.println("Введите число x"); double x = Double.parseDouble(reader.readLine().trim()); System.out.println("Введите число E"); double E = Double.parseDouble(reader.readLine().trim()); // дальше непонятно что делать с числами a, x и E } catch (NumberFormatException e) { System.err.println("Неверный формат числа"); } finally { reader.close(); } } } 

    if the problem of performance does not interest you then it’s more convenient than this:

      Scanner scanner = new Scanner ( System.in ); double variable = scanner.nextDouble (); 

    ps Try not to use translit in your programs, it is better to call all variables, functions, classes English names (as is customary). if you want their name to be clear to those who do not understand English, you can write javadoc or comments in Russian.

    pss and as for the task specified by you, rather for everything, an error crept in there. Well, it does not matter :)

      final double a = 5; // введенное вами число final double x = 3; // ввдеенное вами число final int n = 15; // введенное вами число final double e = 100; // введенное вами число // промежуточные данные final double [] array = new double [n]; // ищем результат int i = 0; for ( ; i < n; i++ ) { if ( 0 == i ) { array[i] = a; continue; } array[i] = 0.5 * ( array[i - 1] - 1 + x / ( array[i - 1] - 1 ) ); if ( Math.abs ( array[i] * array[i] - array[i - 1] * array[i - 1] ) < e ) { break; } } System.out.println ( "результат:" + i ); 
    • 3
      In Java, another formatting is accepted. It looks very unnatural because of this. - cy6erGn0m
    • in my home and on the robot the same thing, customized by the requirements of the customer ^ _ ^ - jmu
    • one
      The crazy customer :) - cy6erGn0m

    Most likely, there is an incorrect i-1 index entry in the task. Those. the entry Yi-1 denotes the element preceding Yi, therefore it is not necessary to reduce the value of the element itself by 1.