Showing posts with label Java Programs. Show all posts
Showing posts with label Java Programs. Show all posts

Write  a  Java applet that demonstrates the behavior of a FlowLayout by demonstrating some buttons. The program should have a main method to execute the applet

import  java.awt.Button;
import  java.awt.FlowLayout;
imporjava.awt.Frame;
public  class  FlowLayouttest  extends  Frame
{
public  FlowLayouttest()
    {
setLayout(new  FlowLayout()); add(new  Button("First"));
add(new  Button("Second")); add(new  Button("Third"));
add(new  Button("Fourth")); add(new  Button("Fifth")) ;
setSize(200,200);
     }
public  static void rnain(String a())
  {
new  FlowLayouttest().setVisible(true);
  }
}

A java applet shows how to create a text-area, a radio-button, a ordinary button.

Solution:
import  java.applet.Applet;
import  java.awt.Button;
import  java.awt.Checkbox;
import  java.awt.CheckboxGroup;
import  java.awt.TextField;
public  class  GuiApplet extends Applet
{
Button okButton;
TextField nameField;
CheckboxGroup  radioGroup;
Checkbox  radiol;
Checkbox  radio2;
Checkbox  option;
public  void  init()
{
setLayout(null);
okButton =  new Button("A button");
nameField =  new TextField("A TextField", 100) ,
radioGroup =  new  CheckboxGroup();
radiol=  new Checkbox("Radiol",  radioGroup,false);
radio2=  new Checkbox("Radio2",  radioGroup,true);
option=  new  Checkbox("Option",false);
okButton.setBounds(20,20,100,30);
nameField.setBounds(20,70,100,40);
radiol.setBounds(20,120,100,30);
radio2.setBounds(140,120,100,30); option.setBounds(20, 170,100,30) ; add(okButton);
add(nameField);
add(radiol);
add(radio2);
add(option);
}

Write a program in java to calculate a number is even or odd

Import  java.util.*;
Class evenodd
{
Public  static  void  main (String  obj [ ])
{
int  n ;
scanner  sc =new  scanner(system.in);
system.out.println(“Enter  the  number”);
n=sc.nextInt();
if(n%2= =0)
{
System.out.println (“The  given  number    is  even”);
}
else
{
System.out.println(“The  given  number    is  odd”);
          }
     }
}

Write a program in java to calculate a year is leap year or not

import  java.util.*;
class  leap year
{
public  static  void  main (String  obj [ ])
   {
       int  year ;
Scanner  sc=new  scanner(system.in);
System.out.println(“Enter  the  year”) ;
year=sc.nextInt();
if((year % 4= =0 && year % 100!=0)//year % 400= = 0)
system.out.println(“The  year  is  leap  year”);
else
system.out.println (“The  year  is  not  leap year”);
        }
}

Write a program in java to calculate big value of 2 numbers

import  java.util.*;
class big
{
public  static  void  main(String  obj [ ])
   {
      int a, b;
Scanner.sc=new  scanner (system.in);
System.out.println (“Enter  the  value  of  a  &  b”);
a=sc  nextInt ();
b=sc  nextInt ();
if(a>b)
system.out.println(“a  is  big”);
if(b>a)
system.out.println(“b  is  big”)
       }
}

Write a program in java to calculate area of a triangle

import  java.util.*;
import  java.lang.*;
class  triangle
{
public  static  void  main (String  obj [ ])
    {
       int a, b, c, s, tri ;
Scanner  sc=new  scanner (system.in);
System.out.println (“Enter  the  value of  a,  b,  c”);
a=sc  nextInt ();
b=sc  nextInt ();
c=sc  nextInt ();
s=sc  nextInt ();
tri = math.sqrt (s*(s-a)*(s-b)*(s-c));
system.out.println (“Area  of  triangle  is=”+tri);
     }
}

Write a program in java to calculate average of five(5) numbers

import  java.util.*;
class  average
{
public  static  void  main (String obj[  ])
{
     int a, b, c , d, e,tot,avg;
Scanner  sc=new  scanner (system.in);
System.out.println(“Enter  the  value  of  a,b,c,d,e”);
a=sc  nextInt ();
b=sc  nextInt ();
c=sc  nextInt ();
d=sc  nextInt ();
e=sc  nextInt ();
tot=a+b+c+d+e;
avg=tot/5;
system.out.println (“Average of 5 no   is=”+avg);
      }
}

Write a program in JAVA to calculate add of two(2) number

import  java . util.*;
class  add
{
Public  static  void  main (String  obj[])
    {
int  a , b , c ;
Scanner sc=new  scanner (system.in);
System.out.println (“Enter  the  value  of  a  &  b”);
a=sc.nextInt();
b=sc.nextInt();
c=a+b;
system.out.println(“The  addition  is=”+c);
      }
}

Write a program in JAVA to swap number without using 3rd variable


import  java.util.*;
class  swaping
{
   public  static  void  main (String obj[])
       {
           int  a , b;
Scanner  sc=new  scanner (system.in);
System.out.println (“Enter  the  value  of a & b”);
a=sc.nextInt ();
b = sc.nextInt ();
a=a+b;
b=a-b;
a=a-b;
system.out.println(“Value  of  a  &  b  is=”+a+”  “+b);
          }
}

Subscribe

Milan Panda
Admin
About Me | Contact
Copyright 2023-2024 © Programming1011 . 🎀 Developed and Design By- Milan Panda. Happy Holi All Of You 🎀