I have a logic problem.
My code is succesfully compiled, but when running it is not working the way it should.
Briefly explained, I want my program to do a 'simple' add operation.
However there are several conditions to it;
You have to specify how many digits in a number are allowed to be able to add.
And finally to recognize the character '=' or the value 61, to print the result.
However, program is not recognizing the value of the character.
Anyone knows what i'm doing wrong?
/** Un programa que pida un numero de 3 digitos y sume el total */ import java.util.Scanner; public class SumaAvanzada{ public static void main(String[] args ){ Scanner sc = new Scanner(System.in); // Variables e Inicializacion: int filtro; String input = ""; int numerodigit; char digit; int bloc; int totalnum; int total; totalnum = 0; total = 0; int switchoff; switchoff = 0; // Obtiene el string y el numero de digitos permitidos: System.out.println( " Ingrese el numero de digitos permitidos: " ); filtro = sc.nextInt(); System.out.println( " Sumar: " ); do{ input = sc.next(); // Obtiene el numero de digitos de la String: numerodigit = input.length(); // Compara el numero de digitos del string vs. el filtro designado: if ( numerodigit == filtro ){ // Lee cada char del string una a la vez. for ( int e = 0; e < numerodigit; e++ ){ digit = input.charAt(e); int digitval = (int) digit; // Determina la posicion del digito. int A = numerodigit - e; // Si el char tiene un valor de 0 a 9... if ( digitval >= 0 && digitval <= 9 ){ // Multiplica por multiplos de 10 correspondiente a la posicion del digito... bloc = 1; do{ bloc = bloc * 10; A--; } while ( A > 0 ); bloc = bloc * digitval; // y suma el resultado. totalnum = totalnum + bloc; total = total + totalnum; } else if ( digitval == 61 ){ System.out.println( total ); switchoff = switchoff + 1;} else System.out.println ( "Ingrese un numero valido o el symbolo \' = \' ." ); ; ; } } else System.out.println ( "Ingrese un numero valido o el symbolo \' = \' 2." ); }while ( switchoff == 1 ); } }