Javaslipprogram
Javaslipprogram
Write a ‘java’ program to copy only non-numeric data from one file to another file
import java.io.*;
slip2:
Write a java program to display all the vowels from a given string
import java.util.Scanner;
Design a screen in Java to handle the Mouse Events such as MOUSE_MOVED and
MOUSE_CLICK and display the position of the Mouse_Click in a TextField.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
slip3
A) Write a ‘java’ program to check whether given number is Armstrong or not. (Use
static keyword)
import java.util.Scanner;
Define an abstract class Shape with abstract methods area () and volume (). Derive
abstract class Shape into two classes Cone and Cylinder. Write a java Program to
calculate area and volume of Cone and Cylinder.(Use Super Keyword.)
import java.util.Scanner;
slip4:
A) Write a java program to display the alternate characters from a given string.
import java.util.Scanner;
slip 5:
B)Write a java program to accept list of file names through command line and delete
the files having extension “.txt”. Display the details of remaining files such as
FileName and size.
import java.io.*;
class Slip12
{
public static void main(String args[]) throws Exception
{
for(int i=0;i {
File file=new File(args[i]);
if(file.isFile())
{
String name = file.getName();
if(name.endsWith(".txt"))
{
file.delete();
System.out.println("file is deleted " +file);
}
else
{
System.out.println(name + " "+file.length()+" bytes")
}
}
else
{
System.out.println(args[i]+ "is not a file");
}
}
}
}
slip 6:
A) Write a java program to accept a number from user, if it zero then throw user
defined Exception “Number Is Zero”, otherwise calculate the sum of first and last
digit of that number. (Use static keyword).
import java.io.*;
class NumberZero extends Exception
{
NumberZero()
{}
}
class Number
{
static int no;
Number() throws IOException
{
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Enter no");
no=Integer.parseInt(br.readLine());
try
{
if(no==0)
{
throw new NumberZero();
}
cal();
}//end of try
catch(NumberZero e)
{
System.out.println("no is zero");
}
}
void cal()
{
int l=0,r=0;
l = no%10;
//System.out.println("no = "+no);
if(no>9)
{
while(no>0)
{
r = no%10
}
System.out.println("Addotion of first and last digit = "+(l+r));
}
else
System.out.println("Addotion of first and last digit = "+l);
}
}
class Slip19
{
public static void main(String a[]) throws IOException
{
Number n= new Number();
}
}
}
}
slip 7:
A) Define an Interface Shape with abstract method area(). Write a java program to
calculate an area of Circle and Sphere.(use final keyword)
import java.util.Scanner;
interface Shape{
void area();
}
class Circle implements Shape{
final float PI=3.14f;
float areacircle,radius;
Scanner s=new Scanner(System.in);
void accept(){
System.out.print("Enter the Radius of circle : ");
radius=s.nextFloat();
}
public void area(){
areacircle=PI*radius*radius;
}
public void show()
{
System.out.println("Area of circle is : "+areacircle);
}
}
slip 8:
A) Define an Interface Shape with abstract method area(). Write a java program to
calculate an area of Circle and Sphere.(use final keyword)
import java.util.Scanner;
interface Shape{
void area();
}
class Circle implements Shape{
final float PI=3.14f;
float areacircle,radius;
Scanner s=new Scanner(System.in);
void accept(){
System.out.print("Enter the Radius of circle : ");
radius=s.nextFloat();
}
public void area(){
areacircle=PI*radius*radius;
}
public void show()
{
System.out.println("Area of circle is : "+areacircle);
}
}
slip9:
slip 10:
A) Write a java program to count the frequency of each character in a given string.
import java.util.Scanner;
A) Write a menu driven java program using command line arguments for the following:
import java.util.Scanner;
public class calculator {
public static void main(String[] args){
int num1=0,num2=0,option,ex=0;
Scanner sc = new Scanner(System.in);
do{
System.out.println("Enter your choice from the following menu:");
System.out.println("1.Addition \n2.Subtraction \n3.Multiplication \
n4.Division \n5.Exit");
option = sc.nextInt();
if(option>4 || option<0){
if (option==5){
System.out.println("You want to Exit.");
}else
System.out.println("Invalid choice");
}
else{
System.out.print("Enter the first number : ");
num1=sc.nextInt();
System.out.print("Enter the second number : ");
num2=sc.nextInt();
}
switch(option){
case 1:System.out.println("Addition of "+num1+" and "+num2+" is "+
(num1+num2));
break;
case 2:System.out.println("Subtraction of "+num1+" and "+num2+" is
"+(num1-num2));
break;
case 3:System.out.println("Multiplication of "+num1+" and "+num2+"
is "+(num1*num2));
break;
case 4: if(num2==0)
System.out.println("Error!!! In Division denominator cannot be
0!");
else{
System.out.println("In division of "+num1+" by "+num2+" is "+
(num1/num2)+" and remainder is "+(num1%num2));
}
break;
case 5: break;
}
if(option==5){
break;
}else{
System.out.println("Do you want to continue? \n1.Yes \n2.No");
ex=sc.nextInt();
}
}while(ex==1);
sc.close();
}
}
my class program
transpose of matrix
import java.util.Scanner;
class TransposeMatrix {
int i, j,temp;
int row,column;
int array[][];
this.column=column;
array=new int [row][column];
}
TransposeMatrix(int array[][])
{
this.array=array;
this.row=array.length;
this.column=array[0].length;
}
}
}
}
void trans()
{
}
}
array=temp;
}
void display()
{
//displaying the matrix
System.out.println("The above matrix after Transpose is :");
for(i=0;i<row;i++)
{
for(j=0;j<column;j++)
{
System.out.print(array[i][j]+" ");
}
System.out.println(" ");
}
}
}
int row,column;
//creating the instance of TransposeMatrix
//accessing the elements using scanner class
System.out.println("Enter rows:");
Scanner s=new Scanner(System.in);
row = s.nextInt();
import java.util.Scanner;
class AgeNotMatchException extends Throwable
{
AgeNotMatchException(String s)
{
super(s);
}
}
public class CustomException3 {
String name;
int age;
this.name = name;
this.age = age;
try
{
if(age<17 || age>25)
{
throw new AgeNotMatchException("age is not in a rangeof 17
to 25");
}
}
catch(AgeNotMatchException e)
{
System.out.println(e);
}
}
void display()
{
System.out.println("name of the person is "+name);
System.out.println("age of the person is "+age);
}