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

    Nov 25, 2014 · 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. Java If else Statement on String value, with Scanner input

    Aug 29, 2018 · I need to know how to assign String values in Java language, import java.util.Scanner; on an if else Statement algorithm. import java.util.Scanner; public class Compare { public static void main (String []args) { Scanner input = new Scanner(System.in); String name = “Henry”; System.out.println(“Enter a NAME”); name = input.nextLine ...

  3. 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

  4. Java if-else Statement - GeeksforGeeks

    Dec 3, 2024 · The if-else statement in Java is a powerful decision-making tool used to control the program's flow based on conditions. It executes one block of code if a condition is true and another block if the condition is false. In this article, we will learn Java if-else statement with examples. Example: [GF

  5. 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.

  6. Tutorial Java Part 8 : Penggunaan IF Dan ELSE Pada Java

    Jan 23, 2017 · Berikut contoh penulisan dan penggunaan IF dan ELSE pada java : kondisi if akan di jalankan jikalau nilai yang diketahui sama dengan kondisi. dan jika pernyataan tidak sesuai dengan dengan kondisi maka perintah else yang akan di jalankan. contoh kasusnya : Penggunaan IF Dan ELSE.

  7. Strings in If - Else Statements in Java - Stack Overflow

    Aug 2, 2016 · To compare Strings (as with all objects) you need to use the .equals method. What the equality operator does in this case is to compare between the addresses of String variable plant and the new String object it allocated just for that line, "Asparagus" .

  8. Penggunaan If - Else Pada Variabel String (Java) - Blogger

    Jul 27, 2013 · import java.util.Scanner; public class Contoh {public static void main(String[] args) { Scanner masuk = new Scanner (System.in); System.out.print("Nama Makanan\t: "); String NM = masuk.nextLine(); if ("soto".equals(NM) ) System.out.println("Harga = Rp. 7.000,-"); else if ("sate".equals(NM) ) System.out.println("Harga = Rp. 8.000,-");

  9. java - How do I return my string inside an if statement ... - Stack ...

    Oct 31, 2015 · public class Solution { public static String remarkStudent(int score) { // Write your code here if ((score>75)&& (score<=100)) { return "Distinction"; } else if ((score>50)&& (score<=75)) { return "Average"; } else if ((score>30)&& (score<=50)) { return "Below Average"; } else{ return null ; } } }

  10. If-Else Statement in Java - Baeldung

    Jan 8, 2024 · In this tutorial, we’ll learn how to use the if-else statement in Java. The if-else statement is the most basic of all control structures, and it’s likely also the most common decision-making statement in programming. It allows us to execute a certain code section only if a specific condition is met. 2. Syntax of If-Else