Variables in Java is used to store the value of element. There are 3 types of variable: Local, global, static. Learn each type with example and declaration
seen from Israel

seen from Dominican Republic
seen from China
seen from Israel

seen from Singapore
seen from Germany

seen from United States
seen from United States
seen from United Kingdom
seen from Senegal
seen from United States
seen from Denmark
seen from Indonesia

seen from Australia
seen from China
seen from United States
seen from China
seen from China
seen from United States

seen from Dominican Republic
Variables in Java is used to store the value of element. There are 3 types of variable: Local, global, static. Learn each type with example and declaration
How to - Do String Anagrams Java Algorithms
How to – Do String Anagrams Java Algorithms
Description:
How to – Do String Anagrams Java Algorithms
import java.io.IOException; public class AnagramApp { static int size; static int count; static char[] charArray; public static void main(String[] args) throws IOException { String input = "java2s.com"; size = input.length(); count = 0; charArray = new char[size]; for (int j = 0; j < size; j++) charArray[j] =…
View On WordPress
How to - Java String Example Java Algorithms
How to – Java String Example Java Algorithms
Description:
How to – Check if a word is a palindrome Java Algorithms
public class Main { public static void main(String[] args) { String n = "level"; boolean right = true; int f = n.length() - 1; for (int i = 0; i < n.length(); i++) { if (n.charAt(i) != n.charAt(f - i)) { right = false; } } System.out.println("The word is " + right); } }
View On WordPress
How to - Toss Coin Java Algorithms
How to – Toss Coin Java Algorithms
Description:
How to – Toss Coin Java Algorithms
import java.util.Random; class Coin { public String toss() { Random myRand = new Random(); int face = myRand.nextInt(2); if (face == 0) { return "heads"; } else { return "tails"; } } } public class Main { public static void main(String[] args) { Coin coin = new Coin(); int headsCount = 0; int tailsCount = 0; for (int i = 1; i
View On WordPress
How to - Random Roll Dice Java Algorithms
How to – Random Roll Dice Java Algorithms
Description:
How to – Random Roll Dice Java Algorithms
import java.util.Random; public class Main { public static void main(String[] args) { System.out.println("Total is: " + Dice.rollDice(3, 6)); } } class Dice { public static int rollDice(int number, int nSides) { int num = 0; int roll = 0; Random r = new Random(); if (nSides >= 3) { for (int i = 0; i < number; i++) { roll =…
View On WordPress
How to - Make a rock paper scissor game Java Algorithms
How to – Make a rock paper scissor game Java Algorithms
Description:
How to – Make a rock paper scissor game Java Algorithms
import java.util.Random; enum Gesture { rock(1), paper(2), scissors(3); private int type; Gesture(int type) { this.type = type; } public int getType() { return type; } } public class Main { public static void main(String[] args) { String choice = "S"; if (choice.equals("S")) { generateDraw(Gesture.scissors); } else if…
View On WordPress
How to - Get random boolean Java Algorithms
How to – Get random boolean Java Algorithms
Description:
How to – Get random boolean Java Algorithms
import java.util.Random; public class Main { public static final void main(String... args) { Random randomGenerator = new Random(); for (int idx = 1; idx <= 10; ++idx) { boolean randomBool = randomGenerator.nextBoolean(); System.out.println("Generated : " + randomBool); } } }
View On WordPress
How to - Generate very large random numbers Java Algorithms
How to – Generate very large random numbers Java Algorithms
Description:
How to – Generate very large random numbers Java Algorithms
import java.math.BigInteger; import java.util.Random; public class Main { public static void main(String... a) { int n = 16; Random r = new Random(); byte[] b = new byte[n]; r.nextBytes(b); BigInteger i = new BigInteger(b); System.out.println(i); } }
View On WordPress