Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

[HELP] Convert String to INT

$
0
0
Hi, can someone explain why there is an error with my code when I'm trying to convert the string to int?

import javax.swing.JOptionPane;
 public class AdditionQuizDialog{
  public static void main(String[] args){
   int number1=(int)(System.currentTimeMillis()%10);
   int number2=(int)(System.currentTimeMillis()*7%10);
   
   //Enter the answer
   String AnswerString=JOptionPane.showInputDialog("What is "+number1+" + "+number2+" ?");
   
   //Convert String to int
   int Answer=Int.parseInt(AnswerString);
   
   String output="What is "+number1+" + "+number2+" is "+(number1+number2==(int)Answer);
   JOptionPane.showMessageDialog(null, output);
 }
} 

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>