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:
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.
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++)
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++)
You are viewing our Forum Archives. To view or take place in current topics click here.