Create a function without using import scanner and you must create and use a java method in this assignment | x+2 x<= 2 f(x) = | | -x^2 +2x +2 x>2 Name the function f Ask the user to enter a double, calculate and display the resulting value of f(x) +5 pts: loop the ask-and-calculate-and-display loop Your main program should: Get a number (x) Use f to calculate a value of the function Display the result (optional) loop back and repeat Your “f method” should: Accept the value of x Decide which branch to take Calculate the value of f(x) Return it to the main
`Hey,
Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries
Brother since you have mentioned not to import scanner. So, I have taken input fromthe command line argument args[]. In case you need any change please comment. I will help as much as I can.
public class Main {
public static double f(double x){
if(x<=2){
return x+2;
}
else{
return -x*x+2*x+2;
}
}
public static void main(String args[]){
int x;
x=Integer.parseInt(args[0]);
System.out.println("f("+x+") = "+f(x));
}
}

Kindly revert for any queries
Thanks.
Create a function without using import scanner and you must create and use a java method...
1) Create a main() method with a switch statement that calls either a sum() OR factorial() method, depending on what selection the user of the program makes - ask the user to enter a selection (with System.out.println()), create a Scanner then read the user's input with a call to Scanner next(), then call the appropriate method in a switch (the String that was read from the call to Scanner.next() should be what you use as your switch condition). 2) Create...
1) Create a main() method with a switch statement that calls either a sum() OR factorial() method, depending on what selection the user of the program makes - ask the user to enter a selection (with System.out.println()), create a Scanner then read the user's input with a call to Scanner next(), then call the appropriate method in a switch (the String that was read from the call to Scanner.next() should be what you use as your switch condition). 2) Create...
Java 7) Create a method that will be used to test an IQ. This method will receive only a String and a Random object when called, and return an int. In this method you will: create a new Scanner object, say hi to the user by name, get 2 random numbers between 0 and 49, and ask the user what the sum of the 2 numbers is. If the user is correct say "Great Job!", and then assign IQ the...
This is for Java. Create ONE method/function that will return an array containing the row and column of the largest integer i the 2D array. If the largest number is located on row 2, column 1, the method needs to return row 2 and column one. Do not use more than one method. Use the code below as the main. Please comment any changes. in java Given the main, create a method that RETURNS the largest number found in the...
java Create a method that will be used to test an IQ. This method will receive only a String and a Random object when called, and return an int. In this method you will: create a new Scanner object, say hi to the user by name, get 2 random numbers between 0 and 49, and ask the user what the sum of the 2 numbers is. If the user is correct say "Great Job!", and then assign IQ the value...
Searching an array: --Using the template provided, create a method called search that takes an int and an array as parameters. The method search should traverse the array to look for the int. search should print whether it found the int or not, for example: found: 10 did not find: 11 examples (bold face is text entered by user) % java SearchArray 20 found: 20 % java SearchArray 13 did not find: 13 % java SearchArray 100 found: 100 %...
3. Write a Java method (called sumOfSquares) that reads in a sequence of integer numbers using a Scanner object. As each integer is read, the method displays that integer. The method also accumulates the sum of the squares of the integers and displays the sum when all integers are read. The method reads integers until a negative integer is read. The negative integer should not be display or added to the sum of squares. The method will not return a...
Create the following programs in Java {Java1 difficulty} [Please create as simple as possible] a. Ask the user to enter their favorite number and favorite word. Pass both of these values to a method that will print the favorite word vertically the favorite number of times. b. Ask the user to enter 2 integers. Pass the integers to 2 different methods: one method to add the integers and print the sum (from the method); the second method to multiply the...
PLEASE INCLUDE COMMENTS In java Create a Java Program Add the following comments at the beginning of the file: Your name. The name of the class(es) used in the program. The core concept (found below) for this lesson. The date the program was written. Include a recursive method separate from the main method that will add together all of the even numbers between and including 1 and the value the user supplies. For instance, if the user enters 10 then...
Create a Java program which asks the user how many names they want to enter. The program should then instantiate an array that will hold this many names. The main method should call a method, getNames() to allow the user to enter the names. A for loop should be used in this method. Once the names are entered, the main method should call another method displayNames() which will use a while loop to display the names entered.