-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