d2jsp
d2jsp Forums > Off-Topic > Programmer's Haven > Java, Visual Basic, VBScript > Can Someone Give Me Pseudo Code For This?
Add Reply New Topic New Poll
ferf
Group: Member
Posts: 30,635
Joined: Mar 25 2009
Gold: 50.00
Jan 7 2021 01:03am
I want to take input from a user using Scanner, and converting it to a integer array



so for example, take this input from user using nextline():
17 27 34 18 12 50 22


or something like that....







EDIT:
nvm figured it out :)

Code


Scanner scan = new Scanner(System.in);
System.out.println("Enter an array of integers, and we will find minimum and maximum values!");
System.out.println("Enter the input with a space between each integer!");


String input = scan.nextLine();
String[] numbersAsString = input.split(" ");

int[] numbers = new int[numbersAsString.length];


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


System.out.println("Your integer array values were: ");
for(int elements : numbers) {
System.out.print(elements + " ");
}


This post was edited by ferf on Jan 7 2021 01:23am
Go Back To Java, Visual Basic, VBScript Topic List
Add Reply New Topic New Poll