Java中的向量和数组
我正在处理一个项目,出于某种原因,当我运行它并选择选项B时,它会将我带回菜单,我不知道为什么,它没有执行案例B过程。。。谁能帮我找到我的错误?谢谢 这就是我所做的:Java中的向量和数组,java,arrays,vector,Java,Arrays,Vector,我正在处理一个项目,出于某种原因,当我运行它并选择选项B时,它会将我带回菜单,我不知道为什么,它没有执行案例B过程。。。谁能帮我找到我的错误?谢谢 这就是我所做的: package arreglosprincipal; /** * * @author Thais Arelis */ import java.util.Scanner; public class ProblemasArreglos { Scanner sc= new Scanner(System.in); int
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");
}
}
package-arregosprincipal;
/**
*
*@作者Thais Arelis
*/
导入java.util.Scanner;
公共类问题{
扫描仪sc=新的扫描仪(System.in);
int Arreglos[];
字符串opcion=“”;
公共问题{
}
公共空间Llenarreglo(){
String MenuPrincipal=(“Seleccione lo que desea hacer:”
+“\n A-安格尔瓦洛雷斯”
+“\n B-不正确”
+“\n C-计算市长”
+“\n D-Ordenar Valores”
+“\n E-客车勇气”
+“\n F-Salir”);
做{
System.out.println(MenuPrincipal);
opcion=sc.next();
交换机(opcion){
案例“A”:
案例“a”:
System.out.println(“您希望输入多少数字?”);
内坎蒂达德;
cantidad=sc.nextInt();
Arreglos=新的int[cantidad];
对于(int i=0;i我在eclipse中运行了这些代码,然后它正常运行,只是光标不在System.out.print
下面的新行。另一个现象是按“F”键无法按预期退出
在java中,Object==Object
比较两个引用,而不是它们的值。您可以使用char option
,这是一种基本数据类型,或者使用option.euqals(“F”)
来避免引用比较。在案例“b”下:您编写了“String arregos[]=new String[5]”.你确定吗?阅读你的代码,我认为应该是“Arreglos=new int[5];”