Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

There are several ways to automate Int and Character Sequence using Java. Here are a few examples:

  1. Generating a sequence of integers using a loop:
for (int i = 0; i < 10; i++) {
  System.out.println(i);
}

This will print the numbers 0 to 9 in the console.

  1. Generating a sequence of characters using a loop:
for (char c = 'a'; c <= 'z'; c++) {
  System.out.println(c);
}

This will print the letters a to z in the console.

  1. Converting a string of integers into an array of integers:
String nums = "1 2 3 4 5";
String[] numArray = nums.split(" ");
int[] intArray = new int[numArray.length];

for (int i = 0; i < numArray.length; i++) {
  intArray[i] = Integer.parseInt(numArray[i]);
}

This will create an int array containing the numbers 1 to 5.

  1. Converting a string of characters into a char array:
String str = "Hello world";
char[] charArray = str.toCharArray();

for (char c : charArray) {
  System.out.println(c);
}

This will print each character of the string "Hello world" in the console.