Error with a simple exercise. Math.pow?
in
Programming Questions
•
19 days ago
Greetings,
I am new to this forum and programming in general, I have just started my career as a Engineer in software development
and so far I have loved it...but I don't love the following!
I am doing some textbook exercises to hone my skills and I have come to a problem I cannot yet solve, it regarding the following code you see below, I am new to all of this so I just learned about this selective structures and Math.pow(x,y) for some reason the code works for every operation but the one in case 3, any number I enter yields this:
And oh my god its so ugly! What kind of sorcery spawned this!? Thus I came here willing to humbly learn and ask for assistance. So any help would be VERY appreciated.
P.D: English is not my main tongue so excuse me any typo. I have translated any relevant variables in the code, the description // is just for me.
import javax.swing.*;
//El programa, dados datos como dos variables de tipo entero, num y v, calcula el resultado de una funcion.int num;int v;String valor;double val;
valor= JOptionPane.showInputDialog("Enter 1,2 or 3");num =Integer.parseInt(valor);
valor= JOptionPane.showInputDialog("Enter V");v=Integer.parseInt(valor);
switch(num){case 1: val=100*v;break;case 2: val= Math.pow(100,v);break;case 3: val=100/v;break;default: val=0;break;}
JOptionPane.showMessageDialog(null,val);System.exit(0);
1