# Programming tutorials

## Java program to draw patterns

Theory You have to use nested loops to draw patterns. Just like C, C+ and Python, Java too has basically two types of loops: the for loop and the while loop. The for loop has a specific format which is called for each loop. Likewise, the while loop has a specific format which is called …

## 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 check if a number is Armstrong

Theory Let a1a2a3…an a number of n digits, where a1, a2, a3,…an are the digits of the number. The number will be called if a1n+a2n+a3n+a4n+…….+ann = a1a2a3…an (the number itself) There is only 1 digit in the number from 0 to 9. Now notice that 01 = 0; 11 = 1; 21 = 2; 31 …

## 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 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 …

## 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 …

## 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 = …

## 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 …