Vous êtes sur la page 1sur 3

package calc;

import java.util.Scanner;

public class Calc


{
public static void main(String args[])
{
float a, b, r;
char ch;
Scanner scan = new Scanner(System.in);

do
{
System.out.print("\nEnter your choice for calculation \n");
System.out.print("1. Addition\n");
System.out.print("2. Subtraction\n");
System.out.print("3. Multiplication\n");
System.out.print("4. Division\n");
System.out.print("5. Exit\n\n");
System.out.print("Enter Your Choice : ");
ch = scan.next().charAt(0);
switch(ch)
{
case '1' : System.out.print("Enter Numbers for addition : ");
a = scan.nextFloat();
b = scan.nextFloat();
r = a + b;
System.out.print("Result of addition = " + r);
break;
case '2' : System.out.print("Enter Number for subtraction : ");
a = scan.nextFloat();
b = scan.nextFloat();
r = a - b;
System.out.print("Result of subtraction = " + r);
break;
case '3' : System.out.print("Enter Number for multiplication: ");
a = scan.nextFloat();
b = scan.nextFloat();
r = a * b;
System.out.print("Result Multiplication = " + r);
break;
case '4' : System.out.print("Enter Number for division : ");
a = scan.nextFloat();
b = scan.nextFloat();
r = a / b;
System.out.print("Result of division = " + r);
break;
case '5' : System.exit(0);
break;
default : System.out.print("WRONG CHOICE");
break;
}

}while(ch != 5);
}
}
----------------------------------------------------------------
package floyed;

import java.util.Scanner;
public class Floyed {

public static void main(String args[])


{
int nr, n = 1, c, d;
Scanner in = new Scanner(System.in);

System.out.println("Enter the number of rows ");


nr = in.nextInt();

System.out.println("Floyd's triangle :");

for ( c = 1 ; c <= nr ; c++ )


{
for ( d = 1 ; d <= c ; d++ )
{
System.out.print(n+" ");
n++;
}

System.out.println();
}
}
}
---------------------------------------------------------------

package pyramid;
import java.util.Scanner;

public class Pyramid


{
public static void main(String args[]) {
int n;
Scanner sc = new Scanner(System.in);

System.out.println("Enter the number of rows ");


n =sc.nextInt();

for (int i = 0; i <n ; i++) {


for (int j = 0; j < n - i; j++) {
System.out.print(" "); }
for (int k = 0; k <= i; k++) {
System.out.print("* "); }
System.out.println(); }
}

}
--------------------------------------------------

package quadequ

import java.util.*;
class Quadequ
{
public static void main(String args[])
{
double x, y, z;
double r1, r2;
double d, sqr;
System.out.println("\nEnter The Values");
Scanner sc = new Scanner(System.in);
System.out.println(" x: ");
x = sc.nextFloat();
System.out.println(" y: ");
y = sc.nextFloat();
System.out.println(" z: ");
z = sc.nextFloat();
d = y*y - 4*x*z;
sqr = Math.sqrt(d);
if(d<0)
{
System.out.println("\n Roots Are Imaginary \n");
}
else
{
r1 = (-y + sqr) / (2*x);
r2 = (-y - sqr) / (2*x);
System.out.println("\n Value of Root 1 = " + r1 + "\n");
System.out.println("\n Value of Root 2 = " + r2 + "\n");
}
}
}

Vous aimerez peut-être aussi