The program gets an integer from the user and gets a line from user and checks if they are integer and keeps them if they are.
I want to get a line from user in a loop that checks if each value is an integer or not,and then put it into a string of characters.(I will be using the values as integer later). I tried getting the values as an integer from the first, but it still doesn't work(?)(I printed it and got 0) This is my overall work:
package spaceship;
import java.util.Scanner;
public class SpaceShip {
static int meteorNumber; //For taking the numbers of meteors in the beginning of the game.
static String firstLine=""; //For taking the values of the first line.
static String secondLine=""; //For taking the values of the second line.
static int i; //Used for the loops.
public static void gamePlace() {
Scanner get = new Scanner(System.in); //For taking the values from user.
System.out.println("Please enter your desired number of meteors and the first line:");
meteorNumber = get.nextInt();
for(i=0;i<7*meteorNumber;i++) {
if(get.hasNextInt() || get.hasNextDouble())
firstLine += String.valueOf(i);
}
System.out.println(firstLine);
}
public static void main(String[] args) {
gamePlace();
}
}
input should be something like this:
The first line of the input in this picture is meteorNumber+firstLine. I have yet to write the code for the second line.
So for the first line,I want to keep the integer values so that I can use them later.I will probably store them in some kind of character array first,but for some reason the string doesn't take the integer values.