Data input

Data input

I need to pass some data from the user to my applet (or application) which is to be entered from the keyboard, using TextField.

The data is repetitive (it fills an array), so when the user enters data for one field of an array, he is to enter another, and another and so on, until all the data is entered.After that, user must enter data from the same TextField into another array, for example, and so on, until everything is known.Because of the amount of data, I can’t use parameters in the APPLET tag.

This whole thing should be similar to something like this in C:

while(entering_data1){   printf(“Please enter data”);   scanf(“%s”,&data1[x]);}…while(entering_data2){   printf(“Please enter data”);   scanf(“%s”,&data2[y]);}

The following code fills a two-dimensional array with numbers read fromstdin. The code takes advantage of the fact that Java methods canreturn arrays as values, hence the line:

 nums[i] = readArray(, M);
can be placed in a loop, and the dirty work of actually readingnumbers can be encapsulated inside readArray.The only option remaining was to read an entire line with
This works, but maybe not for long. JDK1.1 declares readLine obsolete. The preferred technique is to use the readLine method of the BufferedReader class:
BufferedReader din = new BufferedReader(new InputStreamReader(in));   …   result[i] = din.ReadLine();
Hope this gives you some ideas:
import*;public class ReadDemo {   private static int[] readArray(InputStream in, int m) {      int[] result = new int[m];      DataInputStream din = new DataInputStream(in);      String digits;      for(int i = 0; i < m; i++) {         System.out.print("enter a number: ");         // System.out.flush();         try {             digits = din.readLine();             result[i] = Integer.valueOf(digits).intValue();          }         catch(IOException e) {            System.out.println('
' + e.toString());            System.exit(1);         }      }            return result;   }   public static void main(String[] args) {      int M = 2, N = 2;      int[][] nums = new int[N][M];      for(int i = 0; i < N; i++)          nums[i] = readArray(, M);      System.out.println("Here are your numbers: ");      for(int j = 0; j < N; j++) {         for(int k = 0; k < M; k++)            System.out.print(" " + String.valueOf(nums[j][k]));         System.out.println('
');      }   }}

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several