You are viewing our Forum Archives. To view or take place in current topics click here.
[Java] If / Else statement
Posted:

[Java] If / Else statementPosted:

Vysmo
  • New Member
Status: Offline
Joined: May 17, 201113Year Member
Posts: 6
Reputation Power: 0
Status: Offline
Joined: May 17, 201113Year Member
Posts: 6
Reputation Power: 0
I've recently been trying to learn Java and I came up with this. It's very basic and all it does is take an input and compares it to the a predefined value using the If and Else statements.


import javax.swing.*;

public class Main{
   public static void main(String args[]){
      
      String num = JOptionPane.showInputDialog("Please enter the number 10!");
      
      int num1 = Integer.parseInt(num);
      
      if(num1 == 10){
         JOptionPane.showMessageDialog(null, "You have entered the number 10!", "Input Value", JOptionPane.PLAIN_MESSAGE);
         }
      else{
         JOptionPane.showMessageDialog(null, "You were supposed to enter the number 10!", "Input Value", JOptionPane.PLAIN_MESSAGE);
         
      }
   }
}


You enter the number 10 and it returns a message saying you have done so, otherwise it tells you that you should've entered the number 10, extremely basic using skills I picked up from learning off of TheNewBoston on YouTube (A user I would highly recommend if you're learning anything from Java to PHP to C++)
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.