Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class UsingIf {
- public static void main(String[] args) {
- int player1Health = 200;
- int player2Health = 300;
- if (player1Health == player2Health) {
- System.out.println("Draw");
- }
- if (player1Health < player2Health) {
- System.out.println("Winner is player 2");
- }
- if (player1Health > player2Health) {
- System.out.println("Winner is player 1");
- }
- Scanner sc = new Scanner(System.in);
- System.out.println("Please enter a number");
- int num = sc.nextInt();
- // Less than.
- if (num < 100) {
- System.out.println("The number you entered was less than 100");
- }
- // Greater than.
- if (num > 100) {
- System.out.println("The number you entered was greater than 100");
- }
- // Greater than or equal to.
- if (num >= 50) {
- System.out.println("The number you entered was greater than or equal to 50");
- }
- // Less than or equal to.
- if (num <= 50) {
- System.out.println("The number you entered was less than or equal to 50");
- }
- // equals.
- if (num == 10) {
- System.out.println("The number you entered was equal to 10");
- }
- // Not equal to.
- if (num != 15) {
- System.out.println("The number you entered was not equal to 15");
- }
- System.out.println("Please enter your name:");
- String name = sc.next();
- // equals.
- if (name.length() == 10) {
- System.out.println("The length of your name is equal to 10 characters!");
- }
- // greater than.
- if (name.length() > 5) {
- System.out.println("The length of your name is longer than 5 characters!");
- }
- // Not equal to.
- if (name.length() != 25) {
- System.out.println("The length of your name is not equal to 25 characters!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment