CALCULATOR

on 2:19 PM

import java.io.*;
import java.util.*;
public class calculator

{
public static void main(String[] args) throws IOException
{
BufferedReader keyboard = new BufferedReader (new InputStreamReader (System.in));
String input, input1, input2;
int num1, num2, answer;

System.out.println ("\t\t\tWelcome to the calculator!");
do
{
System.out.print ("\nWould you like to Multiply(m), Divide(d), Subtract(s), Add(a)?: ");
input = keyboard.readLine();
if (input.equals("m"))
{
System.out.print ("Please enter the first number!: ");
num1 = Integer.parseInt (input1 = keyboard.readLine());
System.out.print ("Please enter the second number!: ");
num2 = Integer.parseInt (input2 = keyboard.readLine());
answer = num1*num2;
System.out.print ("You chose to multiply."+"\t"+"The Product is: "+answer);
}
if (input.equals("d"))
{
System.out.print ("Please enter the first number!: ");
num1 = Integer.parseInt (input1 = keyboard.readLine());
System.out.print ("Please enter the second number!: ");
num2 = Integer.parseInt (input2 = keyboard.readLine());
answer = num1/num2;
System.out.print ("You chose to divide."+"\t"+"The Dividend is: "+answer);
}
if (input.equals("a"))
{
System.out.print ("Please enter the first number!: ");
num1 = Integer.parseInt (input1 = keyboard.readLine());
System.out.print ("Please enter the second number!: ");
num2 = Integer.parseInt (input2 = keyboard.readLine());
answer = num1+num2;
System.out.print ("You chose to add."+"\t"+"The Sum is: "+answer);
}
if (input.equals("s"))
{
System.out.print ("Please enter the first number!: ");
num1 = Integer.parseInt (input1 = keyboard.readLine());
System.out.print ("Please enter the second number!: ");
num2 = Integer.parseInt (input2 = keyboard.readLine());
answer = num1-num2;
System.out.print ("You chose to subtract."+"\t"+"The Diffrence is: "+answer);
}

System.out.print ("\nWould you like another calculation (y/n)?: ");
input = keyboard.readLine();
}
while(input.equals("y"));
if(input.equals("n"));
System.exit(0);
}
}

twodimensional.java

on 2:19 PM

import java.io.*;
class twodimensional
{
public static void main(String args[])
{
float b[][]=new float [4][5];
int i,j;
float k=0;
for(i=0;i<4;i++)
for(j=0;j<5;j++)
{
b[i][j]=k;
k++;
}
for(i=0;i<4;i++)
{
for(j=0;j<5;j++)
System.out.println(b[i][j]+"");
System.out.println();
}
}
}

fibonacci.java

on 2:15 PM

package com.gpt;


import javax.swing.JOptionPane;
/*
This program computes Fibonacci numbers using a recursive
method.
*/
public class Fibonacci
{
public static void main(String[] args)
{
String input = JOptionPane.showInputDialog("Enter n: ");
int n = Integer.parseInt(input);
for (int i = 1; i <= n; i++)
{
int f = fib(i);
System.out.println("fib(" + i + ") = " + f);
}
System.exit(0);
}
/**
Computes a Fibonacci number.
@param n an integer
@return the nth Fibonacci number
*/
public static int fib(int n)
{
if (n <= 2)
return 1;
else
return fib(n - 1) + fib(n - 2);
}
}

figure.java

on 2:14 PM

abstract class figure
{
double d1,d2;
figure(double x,double y)
{
d1=x;
d2=y;
}
public abstract double area ();
}
class rectangle extends figure
{
rectangle(double a,double b)
{
super (a,b);
}
public double area ()
{
System.out.println("area of the rectangle is");
return d1*d2;
}
}
class triangle extends figure
{
triangle (double p,double q)
{
super(p,q);
}
public double area()
{
System.out.println("area of the triangle");
return(d1*d2)/2;
}
public static void main(String args[])
{
//figure f= new figure();
rectangle r= new rectangle(10,20);
triangle t= new triangle (15,20);
figure ff;
ff=r;
ff.area();
ff=t;

}
}

studentdemo.java

on 2:09 PM

import java.io.*;
class student
{
int rollno;
string name;
long marks;
char grades;
void fill details()
{
roll no=121;
name='uzair';
marks=270;
grades='A';
}
void showdetails()
{
system.out.println("roll no:"=roll name);
system.out.println("name:"+name);
system.out.println("marks:"+marks);
system.out.println("grades of the students is grades");
}
}
class studentdemo
{
public static void main(string a[])
{
system.out.println("this is main menu");
{
studnet st = new student();
st.filldetails();
st.showdetails();
}
}