Posts

Showing posts from November, 2021

Write a java programme using functions to print the following pattern in java .

 public class mul{               static void pattern (int n){     for (int i=0; i<n; i++){     for (int j=0; j<i+1; j++){         System.out.print("*");}         System.out.println();}}     public static void main (String args[]){               pattern(5); } }

Write a java method to print multiplication table of a number n.

public class mul{          static void mult(int x){     for (int i=1; i<=10; i++){     System.out.format ("%d X %d =%d\n",x,i,x*i);     }}     public static void main (String args[]){          mult(3); } }

Write a java programe to reverse an array .

 // Write a java programe to reverse an array . public class nilesh {     public static void main (String args[]){         int [] revers ={1,2,3,4};                  for (int i=3; i>=0; i--){             System.out.print(revers[i]+" ");             } }}

Create a java programe to add two matrices of size 2 X 3 . java array

 // Create a java program to add two matrices . public class nilesh {     public static void main (String args[]){                    int [][] mat1= { {1,2,2},     // First matrics                                     {1,1,2} };           int[][] mat2={{5,5,2},      // Second matrics.                                   {1,2,2}};           int [][] res ={{0,0,0},                                       {0,0,0}};                                          for (int i=0; i<...

Write a java programe to find out the given no. is present in array or not .

 public class Nilesh{     public static void main (String args []){         int num=4;                  int []marks={1,2,3,4,5};         boolean isInArray=false;         for (int element  : marks){             if (element==num){                 isInArray=true;                 break;}}                          if (isInArray){                     System.out.println("Number is present in these array");}             else {                     System.out.println("Number is not present in these array");}         }         }

Create an array of 5 floats and calculate their sum in java .

 //Create an array of 5 floats and calculate their sum . public class Nilesh {     public static void main (String args[]){        float addition=0;         int i=0;         // Creating an array sum         // Declaration +Initialization + memory allocation attomatically.         float [] sum ={1.2f , 2.15f, 5.1f, 8.3f, 9.2f};         for (i =0; i<sum.length; i++){                  addition=addition +sum[i];         }             // Printing addition using format specifier.              System.out.printf("Addition of 5 float no. is =%f",addition);        

Java programme to print multiplication table in reverse order.

 public class nilesh {     public static void main (String args[]){        int n=3;        int i;        for (i=10;  i>0; i--){            int m=n*i;            System.out.printf("%d X %d =%d \n", n, i,m);}}     }

Java programme to print multiplication table of a given numeber.

public class Nilesh{     public static void main (String args[]){         int n=10;  // n is also achieve by user with the help of Scanner function          int i;         for (i=1; i<11; i++ ){             int mult=n*i;             System.out.printf("%d X %d =%d \n",n,i,mult);}}}

Java programme to print first n even numbers using while loop

 import java.util.Scanner ;  public class nilesh {     public static void main (String args[]){         System.out.println("Enter the number :: ");         Scanner sc=new Scanner (System.in);         int n=sc.nextInt();          int i=0;           int sum=0;                while (i<n){                 i++;                 sum=sum+(2*i);                 }              System.out.printf("Sum of %d even no is =%d",n,sum);}}    

Java Programme to print first n even numbers using for loop .

import java.util.Scanner ;  public class nilesh {     public static void main (String args[]){         System.out.println("Enter the number :: ");         Scanner sc=new Scanner (System.in);           int sum=0;            int i,n=sc.nextInt();            for (i=0; i<n; i++){               sum=sum+(2*i);           }               System.out.printf ("Sum of %d no is =%d  ",n, sum );}}

JAVA PROGRAMME TO PRINT FIRST N NATURAL NO. IN REVERSE ORDER

import java.util.Scanner ; public class Nilesh_Deore { public static void main(String[] args) { Scanner sc=new Scanner (System.in); System.out.println("Enter the even number you want to print "); int i,j; i =sc.nextInt(); for (i=i; i>=0; i--){     System.out.println(2*i);} } }