//Program to print multiplication table up to n numbers
import java.util.*;
class mtable
{
public static void main(String args[])
{
int n,m,i,k;
System.out.println(" Up to which number you want to print tables:");
Scanner obj=new Scanner(System.in);
m=obj.nextInt();
System.out.println("\n Tables upto "+m);
for(n=1;n<=m;n++)
{
for(i=1;i<=10;i++)
{
System.out.println("\t"+n+" X "+i+" = "+n*i);
}
System.out.println("\n");
}
}
}
30 August 2018
Java Program to print multiplication table up to n numbers
Java Program to print multiplication table of a given number.
//Program to print multiplication table of a given number.
import java.util.*;
class table
{
public static void main(String args[])
{
int n,i;
System.out.println(" Enter a number to find its multiplication table :");
Scanner obj=new Scanner(System.in);
n=obj.nextInt();
System.out.println("Table of "+n);
for(i=1;i<=10;i++)
{
System.out.println("\t"+n+" X "+i+" = "+n*i);
}
System.out.println( );
}
}
Java Program to sort a list of integers in ascending order
//Program to sort a list of integers in ascending order
import java.util.*;
class ascend
{
public static void main(String args[])
{
int n,i,j,temp;
int a[]=new int[50];
System.out.println(" How many numbers you want to sort in Ascending order:");
Scanner obj=new Scanner(System.in);
n=obj.nextInt();
System.out.println(" Enter elements");
for(i=0;i<n;i++)
{
a[i]=obj.nextInt();
}
System.out.println(" unsorted array : ");
for(i=0;i<n;i++)
{
System.out.print("\t "+a[i]);
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
System.out.println("\n sorted array in ascending order ");
for(i=0;i<n;i++)
{
System.out.print("\t "+a[i]);
}
System.out.println( );
}
}
Java Program to sort a list of integers in descending order
//Program to sort a list of integers in descending order
import java.util.*;
class descend
{
public static void main(String args[])
{
int n,i,j,temp;
int a[]=new int[50];
System.out.println(" How many numbers you want to sort in descending order:");
Scanner obj=new Scanner(System.in);
n=obj.nextInt();
System.out.println(" Enter elements");
for(i=0;i<n;i++)
{
a[i]=obj.nextInt();
}
System.out.println(" unsorted array : ");
for(i=0;i<n;i++)
{
System.out.print("\t "+a[i]);
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(a[j]<a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
System.out.println("\n sorted array in descending order ");
for(i=0;i<n;i++)
{
System.out.print("\t "+a[i]);
}
System.out.println( );
}
}
import java.util.*;
class descend
{
public static void main(String args[])
{
int n,i,j,temp;
int a[]=new int[50];
System.out.println(" How many numbers you want to sort in descending order:");
Scanner obj=new Scanner(System.in);
n=obj.nextInt();
System.out.println(" Enter elements");
for(i=0;i<n;i++)
{
a[i]=obj.nextInt();
}
System.out.println(" unsorted array : ");
for(i=0;i<n;i++)
{
System.out.print("\t "+a[i]);
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(a[j]<a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
System.out.println("\n sorted array in descending order ");
for(i=0;i<n;i++)
{
System.out.print("\t "+a[i]);
}
System.out.println( );
}
}
29 August 2018
C++ Program to find average of n numbers
//Program to find average of n numbers
#include<iostream>
using namespace std;
int main()
{
int n,i,a[100];
float avg,sum=0;
cout<<"\n Of how many number you want to find average:";
cin>>n;
cout<<"\n Enter numbers:"<<endl;
for(i=0;i<n;i++)
{
cin>>a[i];
}
for(i=0;i<n;i++)
{
sum=sum+a[i];
}
avg=sum/n;
cout<<"\n Average of "<<n<<" numbers is :"<<avg<<endl;
return 0;
}
C++ Program to check a given numbers is positive,negative (or) zero
//Program to check a given numbers is positive,negative (or) zero
#include<iostream>
using namespace std;
int main()
{
int n;
cout<<"\n Enter a number:";
cin>>n;
if(n<0)
cout<<"\n Entered number is negative "<<endl;
else if(n==0)
cout<<"\n Entered number is Zero "<<endl;
else
cout<<"\n Entered number is positive"<<endl;
return 0;
}
28 August 2018
Java Program to calculate the discriminant of quadratic equation
//Program to calculate the discriminant of quadratic equation
import java.util.*;
class quadratic
{
public static void main(String args[] )
{
double a,b,c,k;
Scanner obj=new Scanner(System.in);
System.out.println("Enter Co-efficients value");
a=obj.nextDouble();
b=obj.nextDouble();
c=obj.nextDouble;
k=b*b-4*a*c;
if(k<0)
System.out.println("\n It has no real solutions");
else if(k>0)
System.out.println("\n It has two real solutions");
else
System.out.println("\n It has one real solution");
}
}
Subscribe to:
Posts (Atom)
To convert from Upper case to lowercase(A to a)
//converting from Upper to lower(A to a) import java.util.*; class case { public static void main(String args[]) { System.out.pr...
-
//Program to calculate area of circle using SWITCH statement import java.util.*; class switch1 { public static void main(String a...
-
Perfect number : is a positive integers which is equal to the sum of its proper positive divisors, that is, the sum of its positive...
-
//Program to calculate area of circle using if-else statement import java.util.*; class areaofc { public static void main(String ...