About 1,090,000 results
Open links in new tab
  1. java - How do I make a if-else statement with the string

    Nov 25, 2014 · You should use it like this: if (input.equals(yes)) { System.out.println("Your name is: " + name); } else if (input.equals(no)) { System.out.println("Enter your name again"); } Because the statement: input==yes; only checks if the references are equal or not. And to input more values from the user you can do it like this:

  2. How to Compare String With the Java if Statement | Delft Stack

    Feb 12, 2024 · In this guide, we’ll explore various methods and operators within the context of using the if statements for string comparison in Java. Compare String With the Java if Statement Using the == and != Operators

  3. Java if statement - GeeksforGeeks

    Nov 22, 2024 · The Java if statement is the most simple decision-making statement. It is used to decide whether a certain statement or block of statements will be executed or not i.e. if a certain condition is true then a block of statements is executed otherwise not. Example:

  4. java - IF statement using strings - Stack Overflow

    Sep 25, 2012 · In plain English, your first if-statement says: If the person isn't being picked up from CBD AND they're not being dropped off to CBD, then charge them $15. As a result, if neither the pickup or drop-off location is CBD (even if one of …

  5. java - If statement using string - Stack Overflow

    Sep 28, 2013 · String carSize = input.next(); System.out.println("How many days do you wish to rent this?"); int rentalDays = input.nextInt(); if (carSize.equals("luxury")) { System.out.println("Will you be wanting a chauffer (y or n"); String chauffer = input.next(); LuxuryCarRental rentIt = new LuxuryCarRental(renterName, renterZipcode, carSize, rentalDays ...

  6. Java if...else (With Examples) - Programiz

    The Java if...else statement is used to run a block of code under a certain condition and another block of code under another condition. In this tutorial, we will learn about if...else statements in Java with the help of examples.

  7. How to compare String with the Java if statement - javawhizz.com

    Aug 11, 2023 · In this tutorial, you will learn how to compare a String with the Java if statement. The equals () method is a method from the String class that compares two Strings. Let’s look at an example to understand how this method works. To compare a String to another String. Create a String and call the equals () method of the String.

  8. Java If ... Else - W3Schools

    Java has the following conditional statements: Use if to specify a block of code to be executed, if a specified condition is true; Use else to specify a block of code to be executed, if the same condition is false; Use else if to specify a new condition to test, if the first condition is false; Use switch to specify many alternative blocks of ...

  9. Java || Using If Statements, Char & String Variables

    Apr 1, 2021 · In line 26 I used an “If/Else Statement” to determine if the user inputted value matches the predefined letter within the program. I also used the “ OR ” operator in line 26 to determine if the letter the user inputted was lower or uppercase.

  10. How can I write an "if" statement for a string variable in Java?

    Feb 12, 2011 · public static void main(String[] args) { Scanner input = new Scanner( System.in ); float hours; . float rate; . String name; float total_pay; System.out.println("Please enter employee name"); . name = input.next();

Refresh