write the class name please. Declarations 2 points 12) The first numbers of the
ID: 3774443 • Letter: W
Question
write the class name please.
Explanation / Answer
Hi, friend you have not mentioned about Programming Language, but you asked for Class.
So,I have answered in Java.
I habe answered first two questions.
Please repost others in separate post.
Please let me know in case of any issue.
1)
import java.util.Scanner;
public class Fibonacci {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("How many of fibonacci sequence numbers ");
int n = sc.nextInt();
if(n==1){
System.out.println(0);
}
else if(n == 2){
System.out.println(0+" "+1);
}
else{
// if n > 2
System.out.print(0+" "+1+" ");
int f1= 0, f2 = 1;
// iterate to calculate 3rd to nth element
for(int i=3; i<=n; i++){
int f = f1+f2;
System.out.print(f+" ");
f1 = f2;
f2 = f;
}
}
}
}
/*
Sample run:
How many of fibonacci sequence numbers 10
0 1 1 2 3 5 8 13 21 34
*/
2)
import java.util.Scanner;
public class Hypotanous {
static Scanner sc = new Scanner(System.in);
// function to get side of a triangle
public static double getSide(){
System.out.print("Enter side: ");
double side = sc.nextDouble();
return side;
}
public static double getHypotanous(double side1, double side2){
return Math.sqrt(side1*side1 + side2*side2);
}
public static void display(double h){
System.out.println("hypotanous: "+h);
}
public static void main(String[] args) {
double side1 = getSide(); // getting side1
double side2 = getSide();
double hypotanous = getHypotanous(side1, side2);
display(hypotanous);
}
}
/*
Sample run:
Enter side: 4
Enter side: 3
hypotanous: 5.0
*/
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.