Java tutorials

Java program to have random number(s) within a specified limit

Code package com.physicsinfo; import java.util.Scanner; public class Main { public static void main(String args[]){ System.out.print(“Enter the highest integer within which you want the random number: “); Scanner sc = new Scanner(System.in); int highest = sc.nextInt(); System.out.print(“How many random numbers do you want to have printed: “); int count = sc.nextInt(); double rand; System.out.println(“Here is/are your …

Java program to have random number(s) within a specified limit Read More »

Java program to check if a number or word is palindrome

package com.physicsinfo; import java.util.Scanner; public class Main{ public static void main(String args[]){ int flag=0; System.out.print(“Enter a number or word and I’ll tell you if it’s palindrome: “); Scanner sc = new Scanner(System.in); String palin = sc.next(); int n = palin.length(); char[] character = new char[n]; for (int i=0;i<n;i++){ character[i] = palin.charAt(i); } for (int j=0;j<=n/2;j++){ …

Java program to check if a number or word is palindrome Read More »

Java program to print the first n prime numbers

package com.physicsinfo; import java.util.Scanner; public class Main { public static void main(String[] args) { int flag=0, limit, count=0; System.out.print(“Enter how many prime numbers do you want to have printed: “); Scanner sc = new Scanner(System.in); limit = sc.nextInt(); System.out.println(“Here are your first “+ limit + ” prime numbers:”); for(int n=2;n<10000;n++){ // 0 and 1 are …

Java program to print the first n prime numbers Read More »

Prime number program in Java

Algorithm Prime numbers are those which are not divisible by any other number apart from 1 and the number itself. Zero (0), one (1) and negative numbers (e.g., -2, -3, -5) are not prime numbers. Java Code package com.physicsinfo; import java.util.Scanner; public class Main { public static void main(String[] args) { int n, flag=0; System.out.print(“Enter …

Prime number program in Java Read More »

Java program to write Fibonacci series

With Recursion package com.physicsinfo; import java.util.Scanner; public class FibonacciCode{ static int n1=0, n2=1, n3=0; static void fibonacci(int count){ if(count>0){ n3 = n1+n2; System.out.print(n3+” “); n1=n2;n2=n3; count–; fibonacci(count); } } public static void main(String args[]){ System.out.print(“Enter hwo many terms you want to see in the fibonacci series: “); Scanner sc = new Scanner(System.in); int count = …

Java program to write Fibonacci series Read More »

Banking system software code in Java

package com.physicsinfo; import javax.swing.*; import java.util.Scanner; class account{ int amount, acc_no; String name; void display(int acct_no, String name, int bal){ System.out.println(acct_no+” “+name+” “+bal); } void deposit(int amnt){ amount = amount +amnt; System.out.println(“Deposit successful. Your new balance is: “+amount); } void withdraw(int wdr){ if (wdr>amount){ System.out.println(“Insufficient balance.”); } else { amount = amount – wdr; System.out.println(“Withdraw …

Banking system software code in Java Read More »