-1
私はプロジェクトに取り組んでいます。何らかの理由でそれを実行してオプションBを選択すると、メニューが戻ってきます。理由は分かりませんが、ケースBの処理をしています...誰か誰が私のミスを見つけるのを助けることができますか?ありがとう!Javaのベクトルと配列
これは私がやったことです:
package arreglosprincipal;
/**
*
* @author Thais Arelis
*/
import java.util.Scanner;
public class ProblemasArreglos {
Scanner sc= new Scanner(System.in);
int Arreglos [];
String opcion=" ";
public ProblemasArreglos(){
}
public void llenarArreglo(){
String MenuPrincipal=("Seleccione lo que desea hacer: "
+"\n A- Ingresar Valores"
+"\n B- Imprimir"
+"\n C- Calcular el mayor"
+"\n D- Ordenar Valores"
+"\n E- Buscar Valor"
+"\n F- Salir");
do{
System.out.println(MenuPrincipal);
opcion=sc.next();
switch(opcion) {
case "A":
case "a":
System.out.println("How many numbers do you wish to enter?");
int cantidad;
cantidad=sc.nextInt();
Arreglos=new int[cantidad];
for(int i=0;i<Arreglos.length;i++){
System.out.println("Please write a number");
Arreglos[i]=sc.nextInt();
}
for(int i=0;i<Arreglos.length;i++){
System.out.println("The numbers are:"+ Arreglos[i]);
}
System.out.println(" ");
break;
case "B":
case "b":
String Arreglos []= new String[5];
String numero;
for(int i=0;i<Arreglos.length;i++){
System.out.println("Numero:");
numero=sc.nextLine();
Arreglos[i]=numero;
}
for(int i=0;i<Arreglos.length;i++){
System.out.println("Los numeros son:"+ Arreglos[i]);
}
break;
}
}while(opcion!="F");
}
}
"b"の場合: "String Arreglos [] = new String [5]"と書いてあります。あなたはそれについて確かですか?あなたのコードを読む私はそれが "Arreglos = new int [5];であるべきだと思います。 – Shondeslitch