java - 我被困在 isVowel 和 printAll 方法上

标签 java methods

我是 Java 新手,到目前为止,我对它还不太了解。这是我的一项作业,我在使用两种方法时遇到了问题。谁能帮我解决这个问题。谢谢 另外我在哪里可以学习何时在方法中使用什么?我看过一些 youtube,这很有帮助,但我们的教科书很模糊。感谢您提前提供的任何帮助。这是我的代码。

/** The public class below is the name of your java program.
*/
import java.util.Scanner;
public class  ProblemSet6 {
  public static void main(String[] args) {
    //Prompt user for a number
    System.out.print("Enter a number: ");
    double userInput = input.nextDouble();


  }//Ending main method

  /**
* Method Description: Write a method, square, that takes in one number      and 
* returns the square of that number.
*
* This method takes in one number and returns one number. Do not use   Math.pow().
*
* @param x: x is the number that double uses from user input to calculate the return
* @returns and will return x squared 
 */      
   public static double square(double x) {
     return x*x;
   }  //end square method

   /**
* Method Description: Write a method, evalQuadratic, that returns the value of the 
* quadratic a(x*x)+bx+c.
*
* @param x: This method takes in four numbers (a, b, c, and x) and returns a single number.
* Note you are not trying to solve for x, it is already given.

* @returns the value of the quadratic as evalQuadratic
 */

   public static double evalQuadratic(double x, double a, double b,    double c) { 
      return (a*(x*x) + b * x + c);  


   } // end of Quadratic Method

   /**
* Method Description: This method will take a number and raise it to the fourth power.
* Use the square Method from above.
* @param x will be the same "x" input from the begining.
* return the answer of whatever is "x" raised to the fourth power
 */

   public static double fourthPower(double x) {
  return square(square(x));

   } //end of fourthPower Method

   /**
* Method Description: This Method will tell you if the number returned    is odd or even.
* Write a method, odd, that takes in one number and returns True when the number is odd and False otherwise.
* Remember what % (mod) operator does and what it means to be an even/odd number.
* This method takes in one number and returns a boolean.
* @ param x will be determined if it is odd or even.
* @ return boolean odd is true and even is false.
 */

    public static boolean odd(double x) {


        //
      if(x % 2 ==0) return false;
      else return true;


    } // end of odd(boolean) Method 

  /*  
* Define a method isVowel(char c) that returns True if the char is a vowel
* ('a', 'e', 'i', 'o', or 'u'), and False otherwise. 
* You can assume that char is a single letter of any case 
* (ie, 'A' and 'a' are both valid).
* This method takes in one char and returns a boolean.
   */
     public static boolean isVowel(char c) {


        //
      if(c == (a | e | i | o | u)) return true;
     else return false;


    } // end of isVowel(boolean) Method 

  /*
* Write a method, printAll, that takes no parameters and returns nothing.
* This method prints out all of the other methods. For any method that needs
* parameters, use any parameters you wish (Scanner or putting numbers in)
   */


     public static void printAll(){  
       System.out.println(square(userInput));
       System.out.println(evalQuadratic(userInput)); 
       System.out.println(fourthPower(userInput));
       System.out.println(odd(userInput));
       System.out.println(isVowel());

    }


} // end of class

最佳答案

import java.util.Scanner;

public class ProblemSet6
{
public static double[] userInput = new double[ 4 ];

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

for( int i = 0; i < 4; i++ )
{
  System.out.print( "Enter a number: " );
  userInput[ i ] = sc.nextDouble();
}

 sc.close();

}

public static boolean isVowel( char c )
{
 if( c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' )
{
  return true;
}else
{
  return false;
}
} 

 public static void printAll()
{
System.out.println( square( userInput[ 0 ] ) );
System.out.println( evalQuadratic( userInput[ 0 ], userInput[ 1 ], userInput[ 2 ], userInput[ 3 ] ) );
System.out.println( fourthPower( userInput[ 0 ] ) );
System.out.println( odd( userInput[ 0 ] ) );
System.out.println( isVowel( 'a' ) );
}
}

关于java - 我被困在 isVowel 和 printAll 方法上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42806392/

相关文章:

java - 在Java中调用获取时间的方法

java - 如何将两个表的数据合二为一?

ruby - 在 Ruby 中查找字符串中某个字符的 # 次出现

ruby-on-rails - Rails 方法在 View 中不可用

methods - 方法返回无效时的 Spring Integration Gateway 回复 channel

java - 在另一种方法中更改 boolean 值?

java - weblogic jmx tomcata php/java 桥接并让 t3 协议(protocol)正常工作

java - 使用有界缓冲区(生产者/消费者)是否可以避免同步方法/死锁的痛苦?

java - 带 IOC 的 Spring REST 服务?

java - 删除具有特定文本值的子节点的 XML 节点