+ 3
Why doesn't this program execute?
what did I forget? https://code.sololearn.com/cD17ll0J4a3A/?ref=app
6 Respostas
+ 1
This might be closer to what you're looking for:
import java.text.MessageFormat;
import java.util.Scanner;
public class Program
{
public static void main(String[] args)
{
System.out.println("enter the number of elements to save word in:");
Scanner sc = new Scanner(System.in);
int n;
n = sc.nextInt();
sc.nextLine(); // remove the remaining return '\n' character from the stream
String[] arr = new String[n];
for(int i = 0;i<arr.length;i++)
{
System.out.println(MessageFormat.format("element number {0}:",i+1)); // i+1 to list starting with 1 instead of 0
arr[i] = sc.nextLine(); // Use nextLine() to get the whole string instead of just up to the 1st space or newline.
}
int input;
input = sc.nextInt() - 1; // Expecting user to input value of element from list above
if(input < arr.length && input >= 0) // Add check to make sure negative value isn't input
{
System.out.println(arr[input]);
}
else
{
System.out.println("i did not find this such element");
}
}
}
+ 4
lol in my defense it's not blind if the text was different.
change ln 11 to:
n = reader1.nextInt();
(gotta match var names)
+ 1
I try it
thank u so much
0
programs can't feel emotions silly goose
0
see the question again Mr.Blind
0
but is not working yet