Java programs



1. Write a program to print multiplication of table.

package anything;

import java.util.Scanner;

public class multiplication_table {

  public static void main(String[] args) {
  System.out.println("Enter number and range:");
  Scanner sc =new Scanner (System.in);
  int n= sc.nextInt();
  int r=sc.nextInt();
  int i;
  for(i=1;i<=r;i++)
 System.out.println(n+"×"+i+"="+n *i);
}
}


2. Write a program to print factorial of a given number.

package anything;

import java.util.Scanner;

public class factorial {

  public static void main(String[] args) {
  System.out.println("Enter number");
  Scanner sc =new Scanner (System.in);

  int n= sc.nextInt();
  int fact=1,i;
  for(i=n; i>=1;i--)
  fact=fact*i;
  System.out.println("factorial : "+fact);
}
}


3. Write a program to print sum of even numbers in "n" natural number

package anything;

import java.util.Scanner;

public class even_sum {

  public static void main(String[] args) {
  System.out.println("Enter number");
  Scanner sc =new Scanner (System.in);
  int n= sc.nextInt();
  int i,even=0;
  for(i=1;i<=n;i++)
  {
  if(i%2==0)
   even=even+i;
  }
 System.out.println("Sum of even number is: "+even);
}
}

I am not responsible if any thing goes wrong...

If you copy and paste these program in your ide then it will give error, if you want to copy this program then after public class then will not give error.