Sunday, February 23, 2020

Java Menu Driven Program

Menu-driven program A program that obtains input from a user by displaying a list of options – the menu – from which the user indicates his/her choice.


import java.util.Scanner;
class MenuDrivenExample
{
public static void main(String []args)
{
int a,b,c;
Scanner s=new Scanner(System.in);
System.out.println("   Enter any two number :"  );
a=s.nextInt();
b=s.nextInt();
do
{
System.out.println("  Choose any operation given below"   );
System.out.println("   1.Addition" );
System.out.println("   2.Subtraction " ) ;
System.out.println("   3.Multiplication" );
System.out.println("   4.Division  ");
c=s.nextInt();
switch(c)    {
case 1:        
 System.out.println("   Addition  :"  + (a+b));       
 break;
 case 2:        
 System.out.println("   Subtraction  :"   +(a-b));      
 break;
 case 3:      
 System.out.println("   Multiplication  :"   +(a*b));   
 break;
 case 4:      
 System.out.println("  Division  :"     +(a/b));
 break;
default: 
if (c==0)
System.out.println("   Program End, Try Again ");
else 
System.out.println("   please choose any operation : ");
break;
}}
while(c !=0);
}
}

Friday, February 14, 2020

Create Marklist in java program.

 

 Marklist in  java program.

 
import  java.util.Scanner;
public class MarkList
{
public void mList(int english,int hindi,int maths,int science,int  history,int malayalam)
{
System.out.println("English :"+english + "Hindi : "+hindi + "Maths : "+maths + "Science : "+science + "History : "+history + "Malayalam : "+malayalam);
float sum;
sum= english+ hindi+ maths+ science+  history+ malayalam;
double percentage=sum/6;
System.out.println("percentage :="+percentage+"%");
}
public static void main(String[] args)
{
MarkList ml=new MarkList();
Scanner sc=new Scanner(System.in);
System.out.println("English:");
int english=sc.nextInt();
System.out.println("Hindi:");
int hindi=sc.nextInt();
System.out.println("Maths:");
int maths=sc.nextInt();
System.out.println("Science:");
int science=sc.nextInt();
System.out.println("History:");
int  history=sc.nextInt();
System.out.println("Malayalam:");
int malayalam=sc.nextInt();
sc.close();
ml.mList(english, hindi , maths , science , history ,malayalam);
}
}

Java program enter Student Details and find total of marks.

import java.util.Scanner;
public class StudentDetails
{
    public static void main(String[] args)
        {
        Scanner sc=new Scanner(System.in);
        System.out.print("Enter your Name:");
        String name=sc.next();
        System.out.print("Enter your Register no:");
        int register =sc.nextInt();
        System.out.print("Enter your Course");
        String course=sc.next();
        System.out.print("Enter your Place");
        String place=sc.next();
        System.out.print("Enter your Class");
        String cls=sc.next();
        System.out.print("Enter your  marks");
        int mark1=sc.nextInt ();
        int mark2=sc.nextInt ();
        int mark3=sc.nextInt ();
       int marks=mark1+mark2+mark3;
        sc.close ();
        System.out.println("\nName :"+name+"\nRegister no :"+register+"\nCourse :"+course+"\nPlace :"+place+"\nClass :"+cls+"\nTotal Marks :"+marks);
   
    }
}

Enter employee salary and find monthly and year salary.

import java.util.Scanner;
public class EmployeeSalary
{
            public void emplo(int a,int b)
        {
            System.out.println( "Monthly earning:"+a);
            System.out.println("Monthly expence:" + b);
                int c;int d;
c=a-b;
d=c*12;
System.out.println("Monthly Slalary:  "+c);
System.out.println("Yearly Salary: "+d );
}
   
    public static void main(String[] args)
        {
            Scanner sc=new Scanner(System.in);
            EmployeeSalary  es=new EmployeeSalary();
            System.out.println("monthly earning:");
            int a=sc.nextInt();
            System.out.println("monthly expence:");
            int b=sc.nextInt();
            sc.close ();
            es.emplo(a, b);
        }
}

Enter Employee Details in java program.

 Employee Details in java program. 

import java.util.Scanner;
public class EmployeeDetails
{
            public void employee(String name, int id ,String address ,int salary ,String stream)
        {
            System.out.println( "Employee name:"+ name);
            System.out.println("Employee id no:" + id );
            System.out.println("Employee address:" +  address );
            System.out.println("Employee salary:" + salary );
             System.out.println("Employee stream:" + stream);
   
        }
   
    public static void main(String[] args)
        {
            Scanner sc=new Scanner(System.in);
            EmployeeDetails ed=new EmployeeDetails();
            System.out.println("Employee name:");
            String name=sc.next();
            System.out.println("Employee id no:");
            int  id=sc.nextInt();
            System.out.println("Employee address");
            String address=sc.next();
            System.out.println("Employee salary");
            int salary=sc.nextInt();
            System.out.println("Employee stream");
            String stream=sc.next();
            sc.close ();
            ed.employee(name , id , address , salary ,stream);
        }
}

BubbleSort in Java Program

 
 
Image result for Bubble Sort in java concept 
 
 

 BubbleSort in Java Program

import java.util.Scanner;
public class BubbleSort
{
    public static void main(String[] args)
        {
        int num,i,j,temp;
        Scanner input = new Scanner(System.in);
        System.out.println("Enter the number of integers to sort :");
        num=input.nextInt();

        int array[ ] =new int [num];

        System.out.println("Enter "+num+"inegers:");

        for (i=0;i<num;i++)
        array[i]=input.nextInt();

        for(i=0;i<(num-1);i++)
        {
            for(j=0;j<num-1-i;j++)
              {
                 if (array [j] >array [j+1]);
                {
                temp= array[ j ];
                array[j]=array[j+1];
                array[j+1]=temp;
                }
        }
    }
           
        System.out.println("Sorted  list of integers:");
            for(i=0;i<num;i++)
                System.out.println(array[i]);
    }
}

Java String Methods programs

Image result for Strings methods in java replace,convert, concept

Java String Mothods programs


1.charAt()


public class A1
{
public static void main(String[] args)
{
String s ="This is Mysure";
String s1= charAt(6);
System.out.println(s1);
}
}


2.Strings Replace,  replace ()


public class StrReplace
{
    public static void main(String[] args)
    {
        StringBuffer a=new StringBuffer("C++ programming is fun");
        System.out.println(a.replace(0,3,"Java"));
       
       
    }
}


3.Strings Insert, insert()


public class StrInsert
{
    public static void main(String[] args)
    {
        StringBuffer a=new StringBuffer("Java programming is ");
        System.out.println(a.insert(20,"fun"));
   

    }
}


4. Strings comparison, compareTo()


import java.util.*;
public class Comp
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a sentence : ");
String s1=sc.next();
String s2="Mysore";
int s3=s1.compareTo (s2);
System.out.println(s3);
}
}



5. Strings equal, equal ()



import java.util.*;
public class Equa
{
public static void main(String[] args)
{
String s1="Mysore";
String s2="Mysore";
Boolean s3=s2.equals(s1);
System.out.println(s3);
}
}


6.contains()


import java.util.*;
public class S9
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter data:");
String a=sc.next();
String s="My";
Boolean s1=s.contains(a);
System.out.println(s1);
}
}

7.Strings Lower case, toLowerCase()


import java.util.*;
public class Lcase
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a Uppercase sentence : ");
String a=sc.next();
sc.close();
String a1=a.toLowerCase();
System.out.println(a1);
}
}

8.Strings Upper case, toUpperCase()


import java.util.*;
public class Ucase
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a lower case sentence : ");
String a=sc.next();
sc.close();
String a1=a.toUpperCase();
System.out.println(a1);
}
}


9.Strings reverse


import java.util.Scanner;
public class ContrString
{
public static void main(String[] args)
{
       
        String original,reverse=" ";
        Scanner in =new Scanner(System.in);
        System.out.println("Enter a string to  reverse");
         original=in.nextLine();
       
        int length=original.length();

        for (int i = length -1 ;i>=0;i--)
            reverse=reverse + original.charAt(i);

        System.out.println("Reverse of entered string is  :" +reverse);
    }
}









Java abstract class example

 
Image result for Abstract class in java  using car concept

 Java abstract  class example 

 

abstract class Car
       {
           int regno;
           car(int r)
           {
              regno = r;
           }
         void opentank()
              {
              System.out.println(“fill the tank”);
           }
        

    abstract void steering(int direction, int angle);
     abstract void braking(int force);
       }
      class maruthi extends car
       {
             maruthi(int regno)
             {
                   super(regno);
             }

    void steering(int direction, int angle)
        {
          System.out.println(“take a turn”);
          System.out.println(“this is ordinary   steering”);
        }
        void braking(int force)
       {
        System.out.println(“breaks applied”);

    

    System.out.println(“these are hydraulic    brakes”);
    }
    class santro extends car
         {
           santro(int regno)
           {
                 super(regno);
           }

    void steering(int direction, int angle)
        {
          System.out.println(“take a turn”);
          System.out.println(“this is uses power   steering”);
        }
        void braking(int force)
       {
           System.out.println(“breaks applied”);
           System.out.println(“this car uses gas    brakes”);
        }
    }

BytesTest in java program

 BytesTest in java program

import java.util.Scanner;
import java.io.*;
class BytesTest
{
public static void main(String arg[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a byte number: ");
String num=sc.nextLine();
Byte b1=new Byte(num);
System.out.println("Enter a another byte number: ");
num=sc.nextLine();
Byte b2=Byte.valueOf(num);
int n=b1.compareTo(b2);
    if (n==0)
            System.out.println ("Both are Same");
                else if(n>0)
                System.out.println (b1 + "is bigger");
                    else
                    System.out.println (b2 + " is bigger");
}
}

Check Vowel sound in java pgm


Image result for vowel or not  in java concept


import java.util.Scanner;
class vowel
{
  public static void main(String[]args)
{
  char a;
  Scanner k=new Scanner(System.in);
  System.out.println("enter any character");
  a=k.next().charAt(0);
int b;
b=(int)a;
b=b-32;
a=(char) b;
switch(a)
{
    case 'A':
    case 'E':
    case 'I':
    case 'O':
    case 'U':
    System.out.println("it's a vowel"+a);
    break;
   default:
     System.out.println("it's not a vowel"+a);
}
}
}

Monday, February 10, 2020

Given four number find Total and Average in C++



C++ program code
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c,d,sum,avg;
cout<<"Enter four number:";
cin>>a>>b>>c>>d;
sum=a+b+c+d;
cout<<"\nSum of four number:"<<sum;
avg=sum/4;
cout<<"\nAverage of four number:"<<avg;
getch();
}   

 JAVA program code
import java.io.*;
class sa
{
public static void main(String []args)
{
int a,b,c,d,sum;
float avg;
try
{
DataInputStream  obj=new DataInputStream(System.in);
System.out.println("  Enter four number :"  );
a=Integer.parseInt(obj.readLine());
b=Integer.parseInt(obj.readLine());
c=Integer.parseInt(obj.readLine());
d=Integer.parseInt(obj.readLine());
sum=(a+b+c+d);
System.out.println("   Sum of four number:" +sum);
avg=(float)sum/400*100;
System.out.println("   Average of four number: " +avg);
}
catch (Exception e)
{
}
}
}

Find the Area and Perimeter of a Rectangle in C++/Java Program


 
Image result for Perimeter of a Rectangle concept?
 
 

Area and Perimeter of a Rectangle in C++ Program 

#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();
float area,perimeter,w,l;
cout<<"Enter Width of Rectancle";
cin>>w;
cout<<"Enter Length of Rectancle";
cin>>l;
area=w*l;
perimeter=2*(l+w);
cout<<" Area of a Rectangle:"<<area;
cout<<" perimeter of a Rectangle:"<<perimeter;
getch();
}

Area and Perimeter of a Rectangle in Java Program 


  import java.util.Scanner;
class AP
{
public static void main(String []args)
{
Scanner  obj=new Scanner(System.in);
float area,perimeter,w,l;
System.out.print("   Enter Width of Rectancle   :");
w=obj.nextFloat();
System.out.print("  Enter Length of Rectancle  :");
l=obj.nextFloat();
area=w*l;
perimeter=2*(l+w);
System.out.println("  Area of a Rectangle  :"  +area);
System.out.println("  perimeter of Rectangle  :" +perimeter);
}
}

find factorial of given a number in C++ / Java Program?

Image result for factorial of  given a number concept?
 
 

Factorial of  given a number in C++ Program

 
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n,f=1,a;
cout<<"\nEnter any number :";
cin>>n;
for(a=1;a<=n;a++)
{
cout<<a<<"\n";
f=f*a;
a++;
}
cout<<"factorial is :"<<f;
getch();
}

Factorial of  given a number in Java Program


 import java.util.Scanner;
class factory
{
public static void main(String []args)
{
int n,f=1,a;
Scanner  obj=new Scanner(System.in);
System.out.println("  Enter a number :"  );
n=obj.nextInt();
for(a=1;a<=n;a++)
{
System.out.println( a);
System.out.println("  "  );
f=f*a;
a++;
}
System.out.println("   Factorial is  :"   +f);
}
}

Sunday, February 9, 2020

Prime or not given number program in C++ and java program

Image result for prime or not given number concept?

Prime or not given number program in C++  Program

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c=0;
cout<<"\nEnter any number :";
//Prime number - 47
cin>>a;
for(b=2;b<=a/2;b++)
{
if (a%b==0)
{
c=1;
break;
}
}
if (c==1)
cout<<"Given number is not Prime";
else
cout<<"Given number is Prime";
getch();
}  


Prime or not given number program in Java  Program


 import java.util.Scanner;
class prime
{
public static void main(String []args)
{
int a,b,c=0;
Scanner  obj=new Scanner(System.in);
System.out.println("  Enter a number :"  );
a=obj.nextInt();
for(b=2;b<=a/2;b++)
{
if (a%b==0)
{
c=1;
}
}
if(c==1)
System.out.println("   Given number is not Prime" );
else
System.out.println("   Given number is  Prime ");
}
}

Kerala state rutronix, pgdca C++/java and data structure using c++, february 2020

Theory question paper 

Kerala State Rutronix , Pratical Examination -july 2018 java Answer




Factors given number program in Java  Program 

Example :- Image result for factors of number 15 concept? 

Image result for factors of 15 number? 

1. Factors of number

import java.util.Scanner;
class factors
{
public static void main(String []args)
{
int Number, i;
Scanner sc = new Scanner(System.in);
System.out.println("Please Enter any number to Find Factors: ");
Number = sc.nextInt();
    for(i = 1; i <= Number; i++)
    {
    if(Number%i == 0)
    {
    System.out.format(" %d  ", i);
    }
    }
}
}

 

 

 2. Factorial of number

 

Image result for factorial of  5 number? 

 import java.util.Scanner;
class factory
{
public static void main(String []args)
{
int n,f=1,a;
Scanner  obj=new Scanner(System.in);
System.out.println("  Enter a number :"  );
n=obj.nextInt();
for(a=1;a<=n;a++)
{
System.out.println( a);
System.out.println("  "  );
f=f*a;
a++;
}
System.out.println("   Factorial is  :"   +f);
}
}

 

Kerala State Rutronix , Pratical Examination -feb 2015 java and C++ Answer









Java Program

import java.util.Scanner;
class calc
{
void maxi( int a,int b)
    {
    if (a>b)
        System.out.println("  Maximum   :" +a);
    else
        System.out.println("  Maximum  :  " +b);
    }
void maxi( int a,int b,int c)
    {
    if (a>b & a>c)   
        System.out.println("  Maximum  :" +a);
            else
        if(b>a & b>c)
                System.out.println("  Maximum  :" +b);
            else
                System.out.println("  Maximum  :" +c);
    }
}
class max
{
public static void main(String[]args)
{
int d,e,f;
calc m=new calc( );
System.out.println(" Enter any three value"  );
Scanner k=new Scanner(System.in);
d=k.nextInt( );
e=k.nextInt( );
f=k.nextInt( );
m.maxi(d,e);
m.maxi(d,e,f);
}
}


 C++ Program

#include<iostream.h>
#include<conio.h>
int max(int a,int b)
{
if (a>b)
cout<<"  Maximum  :"  <<a<<endl;
else
cout<<"  Maximum  :"   <<b<<endl;
}
int max(int a,int b,int c)
{
if (a>b && a>c)
cout<<"   Maximum   :"   <<a<<endl;
else
if (b>a && b>c)
cout<<"  Maximum   :"  <<b<<endl;
else
cout<<"   Maximum   :"   <<c<<endl;
}
void main()
{
clrscr();
int d,e,f;
cout<<"  Enter three integer value:"   <<endl;
cin>>d>>e>>f;
max(d,e);
max(d,e,f);
getch();
}

Kerala State Rutronix , Pratical Examination -feb 2018 C++ Answer




#include<iostream.h>
#include<conio.h>
struct stud
{
char stdname[20]   ;
int reg,m1,m2,m3;
int tot()
{
int t=m1+m2+m3;
return(t);
}

}data;

void main()
{
clrscr();
cout<<"\n\tEnter Student Name:";
cin>>data.stdname;
cout<<"\n\tEnter Student Register No:";
cin>>data.reg;
cout<<"\n\tEnter First Mark:";
cin>>data.m1;
cout<<"\n\tEnter Second Mark:";
cin>>data.m2;
cout<<"\n\tEnter Third Mark:";
cin>>data.m3;

cout<<"\n\t Student Name:"<<data.stdname;
cout<<"\n\t Student Register No:"<<data.reg;
cout<<"\n\t First Mark:"<<data.m1;
cout<<"\n\t Second Mark:"<<data.m2;
cout<<"\n\t Third Mark:"<<data.m3;
cout<<"\n Total:"<<data.tot();
float per=data.tot()
cout<<"\tPersentage:"<<per/300*100;
getch();
}

Writer a c++/java program convert 1.inch to centimetre 2.centimetre to inch 3.Celsius to fahrenheit 4.fahrenheit to celsius Menu driven and repeatedly running ๐Ÿƒ๐Ÿผ‍๐Ÿงanswer




In   C++ program                                                                                                                                                                                                     ๐Ÿ‘‡                                                                                                                                                                            #include<iostream.h>
#include<conio.h>
void main()
{
int ch;
float in,cm,fh,cl;
while(ch!=0)
{
clrscr();
cout<<"Converst";
cout<<"\n\t1. Inch to Centimetre";
cout<<"\n\t2. Centimetre to Inch";
cout<<"\n\t3. Celsius to Fahrenheit";
cout<<"\n\t3. Celsius to Fahrenheit";
cout<<"\n\n\t\tChoose any converstion:";
cin>>ch;
switch(ch)
{
case 1:
cout<<"\nEnter Inch:";
cin>>in;
float c=in*2.54;
cout<<"Centimetre:"<<c;
break;
case 2:
cout<<"\nEnter Centimetre:";
cin>>cm;
float i=cm/0.394;
cout<<"Inch is:"<<i;
break;
case 3:
cout<<"\nEnter Fahrenheit:";
cin>>fh;
float ce=(fh-32)+5/9;
cout<<"Celsius is:"<<ce;
break;
case 4:
cout<<"\nEnter Celsius:";
cin>>cl;
float f=(cl*9/5+32);
cout<<"fahrenheit is:"<<f;
break;
default:
cout<<"noting";
break;
}
getch();
}}




java source code

import java.util.Scanner;
class conv
{
public static void main(String[] agrs)
{
int ch;
float cm,in,fa,cel;

while(true)
{
System.out.println("  1. Inch convert to Centimetre"  );
System.out.println("  2. Centimetre convert to Inch " );
System.out.println("  3. Celcius convert to Fahrennheit"  );
System.out.println("  4.  Fahrennheit convert toCelcius"  );

System.out.println("  Choose any Opertion"  );

Scanner  k=new Scanner (System.in);
ch=k.nextInt( );

switch(ch)
{
case 1:
System.out.println("  Enter Inch "  );
in=k.nextFloat( );
double ctm=(in*2.54);
System.out.println("  Centimetre "   +ctm);
break;
case 2:
System.out.println("  Enter Centimetre"  );
 cm=k.nextFloat( );
 double inc=(cm*0.39);
System.out.println("   Inch is:"   +inc);
break;
case 3:
System.out.println("  Enter Celsius "  );
 cel=k.nextFloat( );
 float f=(cel*9/5+32);
System.out.println("   Fahrenhet is "   +f);
break;
case 4:
System.out.println("  Enter Fahrenhet: "  );
 fa=k.nextFloat();
 float cels=(fa-32)+5/9;
System.out.println("   Celsius is "   +cels);
break;
default:
if(ch==0)
{
System.exit(0);
}
System.out.println("  Nothing,Please try again!"   );
System.out.println("     "   );
System.out.println("     "   );
}
}
}
}

Display the pattern like right triagle with a number program in java

Image result for pattern print in java

Display the pattern like right  Triagle with a number program in java


1
12
123
1234
12345
123456
1234567
12345678
123456789
12345678910

12345678910
123456789
12345678
1234567
123456
12345
1234
123
12
1

10987654321
987654321
87654321
7654321
654321
54321
4321
321
21
1


for(a=12;a<1;a--)
for(b=12;b<a;b--)

System.out.println(b);

if (a==b){
System.out.println();
}




*
**
***

class star
{
public static void main(String[] args)
{
int a;
for(a=0;a<10;a++)
{
System.out.print("*");
while(a=<10)
{
System.out.println("*");
a--;
}}
}