- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 74 Articles for Java Technologies
4K+ Views
Factorial of a positive integer n is the product of all values from n to 1. For example, the factorial of 3 is (3 * 2 * 1 = 6). Algorithm1. Take integer variable A 2. Assign a value to the variable 3. From value, A up to 1 multiply each digit and store 4. The final stored value is factorial of AExampleimport java.util.Scanner; public class Factorial { public static void main(String args[]){ int i, factorial=1, number; System.out.println("Enter the number to which you need to find the factorial:"); Scanner sc = new Scanner(System.in); number = sc.nextInt(); for(i = 1; i
139 Views
public class RegexOccur { public static void main(String args[]) { String str = "java is fun so learn java"; String findStr = "java"; int lastIndex = 0; int count = 0; while(lastIndex != -1) { lastIndex = str.indexOf(findStr,lastIndex); if(lastIndex != -1) { count ++; lastIndex += findStr.length(); } } System.out.println(count); } }Output2
3K+ Views
Following example showcases labels 'first', 'second' before a for statement and use the break/continue controls to jump to that label. See the example below.ExampleLive Demopublic class Tester { public static void main(String args[]) { first: for (int i = 0; i < 3; i++) { for (int j = 0; j< 3; j++){ if(i == 1){ continue first; } ... Read More
423 Views
Java programming language provides following types of decision making or branching statements.Java programming language provides following types of decision making statements.Sr.No.Statement & Description1if statementAn if statement consists of a boolean expression followed by one or more statements.2if...else statementAn if statement can be followed by an optional else statement, which executes when the boolean expression is false.3nested if statementYou can use one if or else if statement inside another if or else if statement(s).4switch statementA switch statement allows a variable to be tested for equality against a list of values.
933 Views
Following program is using labeled for loops.ExampleLive Demopublic class Tester { public static void main(String args[]) { first: for (int i = 0; i < 3; i++) { for (int j = 0; j< 3; j++){ if(i == 1){ continue first; } System.out.print(" [i = " + i + ", ... Read More
2K+ Views
Yes. Java supports labeled statements. You can put a label before a for statement and use the break/continue controls to jump to that label. ExampleSee the example below.Live Demopublic class Tester { public static void main(String args[]) { first: for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++){ if(i == 1){ continue first; ... Read More
218 Views
A switch statement allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each case.SyntaxThe syntax of enhanced for loop is −switch(expression) { case value : // Statements break; // optional case value : // Statements break; // optional // You can have any number of case statements. default : // Optional // Statements }The following rules apply to ... Read More
3K+ Views
| is a bitwise operator and compares each operands bitwise.It is a binary OR Operator and copies a bit to the result it exists in either operands.Assume integer variable A holds 60 and variable B holds 13 then (A | B) will give 61 which is 0011 1101.Whereas || is a logical OR operator and operates on boolean operands. If both the operands are false, then the condition becomes false otherwise it is true. Assume boolean variable A holds true and variable B holds false then (A && B) is true.| is to be used during bitwise operations and || is useful during logical operations.