Reputation:
I would like to be able to make a program that uses the following formula :
z= 1/y (x)
I would like it to ask the following questions:
Enter the number of times that it has occured this year (this part I know how to do) (y)
How many times has it occured today (x)
The only thing I have so far is ......
import java.util.Scanner;
import javax.swing.JOptionPane;
public class javaCalculator
{
public static void main(String[] args)
{
int num1;
int num2;
String operation;
Scanner input = new Scanner(System.in);
System.out.println("please enter the first number");
num1 = input.nextInt();
System.out.println("please enter the second number");
num2 = input.nextInt();
Scanner op = new Scanner(System.in);
System.out.println("Please enter operation");
operation = op.next();
if (operation == "+");
{
System.out.println("your answer is" + (num1 + num2));
}
if (operation == "-");
{
System.out.println("your answer is" + (num1 - num2));
}
if (operation == "/");
{
System.out.println("your answer is" + (num1 / num2));
}
if (operation == "*")
{
System.out.println("your answer is" + (num1 * num2));
}
}
}
can someone help??
Thank you! (i am in high shcool and would like to input a formula I made, but I also need to convert it into html..
Upvotes: 0
Views: 98
Reputation: 2500
You can try something like below:
import java.util.Scanner;
class ComputeXbyY
{
public static void main(String args[])
{
// Using Scanner for Getting Input from User
Scanner in = new Scanner(System.in);
System.out.println("Please enter: y - ");
int y = in.nextInt();
System.out.println("You entered y "+y);
System.out.println("Please enter: x - ");
int x = in.nextInt();
System.out.println("You entered x "+x);
if(y!=0){
float res = (float)x/(float)y;
System.out.println("Result: "+res);
}
in.close();
}
}
Upvotes: 1