Problema al usar un do while junto a una variable string
Publicado por Esteban (2 intervenciones) el 20/06/2021 10:16:46
//en si la idea seria sencilla pide un producto y este me arrojaría el nombre de este y su precio, luego me pediría si quiero ingresar otro con S continuo y con N termino todo bien con N pero si le pongo S no me arroja la parte de ingresar producto sino que me envía a la parte de quiere ingresar otro producto, le realice un debug y al hacerlo me permitió ingresar otro producto luego del do pero este no lo leyó y me arrojo al desea ingresar otro producto.
Nose si me podrían ayudar viendo el error es en JAVA.
Nose si me podrían ayudar viendo el error es en JAVA.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication73;
import java.util.Scanner;
/**
*
* @author Hp
*/
public class JavaApplication73 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner tec= new Scanner (System.in);
String producto, b="0,25 $", c="1,00 $";
String exit;
do{
System.out.println("Ingrese nombre del producto");
producto=tec.nextLine();
producto=producto.trim();
if (val_producto(producto)==true) {
if ((producto.equalsIgnoreCase("Uvas"))||(producto.equalsIgnoreCase("Peras"))) {
System.out.printf("Producto: "+producto.toUpperCase()+" \n"
+"Precio: %s \n" , b);
}
if (producto.equalsIgnoreCase("Sandia")) {
System.out.printf("Producto: "+producto.toUpperCase()+"\n"
+ "Precio: %s \n", c);
}
}else{System.out.println("Solo puede ingresar prodcutos de la lista mostrada");}
System.out.println("Desea inresar otro num? (S/N)");
do{
exit=tec.next().toUpperCase();
if (!exit.matches("[NS]"))System.out.println("Solo puede ingresar S ó N");
}while(!exit.matches("[NS]"));
}while(!exit.equals("N"));
}
public static boolean val_producto(String producto){
for (int i = 0; i < producto.length(); i++) {
if(!Character.isAlphabetic(producto.charAt(i))) return false;
}
return true;
}
}
Valora esta pregunta


0