0% found this document useful (0 votes)
2 views

HW 2

Uploaded by

hrnhg2c6r7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

HW 2

Uploaded by

hrnhg2c6r7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

1-

import java.util.Scanner;

Scanner in = new Scanner (System.in);

double area,radius,length,width,height,major,minor;

System.out.println("shepe:");

String na = in.nextLine();

switch (na)

case "circle":

System.out.println("radius:");

radius = in.nextDouble();

area = radius*radius*3.14;

System.out.println("area = "+area);

break;

case "rectangle":

System.out.println("length:");

length = in.nextDouble();

System.out.println("width:");

width = in.nextDouble();

area = length*width;

System.out.println("area = "+area);

break;

case "square":

System.out.println("length:");

length = in.nextDouble();

area = length*length;

System.out.println("area = "+area);

break;

case "triangle":

System.out.println("length:");
length = in.nextDouble();

System.out.println("width:");

width = in.nextDouble();

area = 0.5*length*width;

System.out.println("area = "+area);

break;

case "oval":

System.out.println("major:");

major = in.nextDouble();

System.out.println("minor:");

minor = in.nextDouble();

area = major*minor*3.14;

System.out.println("area = "+area);

break;

default:

System.out.println("error");

break;

}
2-

import java.util.Scanner;

Scanner in = new Scanner (System.in);

System.out.println("Enter 10 numbers:");

for (int na=1;na<=10;na++)

System.out.println("Nunber:" );

int number = in.nextInt();

int nc=1;

for (int nb=1;nb<=number;nb++)

nc*=nb;

System.out.println("n!="+nc);

}
3-

import java.util.Scanner;

Scanner in = new Scanner (System.in);

int na,count=0;

for (na=1;na<=20;na++)

System.out.println("yes or no:");

String nb=in.nextLine();

if (nb.equals("yse"))

count++;

System.out.println("count="+count);
4-

import java.util.Scanner;

Scanner in = new Scanner (System.in);

double sum=0,na;

System.out.println("item:");

na = in.nextInt();

while (na!=-5)

sum+=na;

System.out.println("item:");

na=in.nextInt();

System.out.println("sum="+sum);

if (sum<500)

System.out.println("discount="+(sum-(sum*0.15)));

else if (sum>=500&&sum<=1500)

System.out.println("discount="+(sum-(sum*0.25)));

else if (sum>1500)

System.out.println("discount="+(sum-(sum*0.32)));

You might also like