java code
here I create 2 classes
I asked the user to enter 2 numbers float or int dosnot matter (here how can I do 1 thing with 2 data type )
then find the max ,mini,+ , - , * , /
the problem is in calling the methods to the main
https://repl.it/join/fysdlqqi-saraalsa
Do you mean this:
class Main { public static void main(String[] args) { OtherClass.someFunction(); } } class OtherClass { // make sure it's static! static void someFunction() { } }
Yes also this I have triple using [email protected]
@SaraAlsa Yeah, so just do that
can you join to see the problem in calling the function
@DynamicSquid
@RYANTADIPARTHI (1083) OK BUT how can I call them in main
I want them out the main class
If you are talking about finding the min, max, and all those symbols for user input, try this code:
- add
import java.util.Scanner; // Import the Scanner class class MyClass { public static void main(String[] args) { int x, y, sum; Scanner myObj = new Scanner(System.in); // Create a Scanner object System.out.println("Type a number:"); x = myObj.nextInt(); // Read user input System.out.println("Type another number:"); y = myObj.nextInt(); // Read user input sum = x + y; // Calculate the sum of x + y System.out.println("Sum is: " + sum); // Print the sum } }
- subtract
import java.util.Scanner; // Import the Scanner class class MyClass { public static void main(String[] args) { int x, y, sum; Scanner myObj = new Scanner(System.in); // Create a Scanner object System.out.println("Type a number:"); x = myObj.nextInt(); // Read user input System.out.println("Type another number:"); y = myObj.nextInt(); // Read user input sum = x - y; // Calculate the sum of x + y System.out.println("Sum is: " + sum); // Print the sum } }
- multiply
import java.util.Scanner; // Import the Scanner class class MyClass { public static void main(String[] args) { int x, y, sum; Scanner myObj = new Scanner(System.in); // Create a Scanner object System.out.println("Type a number:"); x = myObj.nextInt(); // Read user input System.out.println("Type another number:"); y = myObj.nextInt(); // Read user input sum = x * y; // Calculate the sum of x + y System.out.println("Sum is: " + sum); // Print the sum } }
- divide
import java.util.Scanner; // Import the Scanner class class MyClass { public static void main(String[] args) { int x, y, sum; Scanner myObj = new Scanner(System.in); // Create a Scanner object System.out.println("Type a number:"); x = myObj.nextInt(); // Read user input System.out.println("Type another number:"); y = myObj.nextInt(); // Read user input sum = x / y; // Calculate the sum of x + y System.out.println("Sum is: " + sum); // Print the sum } }
Tell me if you need more.
@RYANTADIPARTHI also I want from the user to enter number and the user maybe enter integer or float
@SaraAlsa yeah, if you want that, you can just put a int, or float method around it.
How can you show me exactly [email protected]
@SaraAlsa wherever you see the nextInt()
in my code i gave you. Just change it to whatever you want like float, and str.
I know this point but my teacher tell me that the user will enter a number (float , int ) I don’t know and my program should do the functions on these 2 number whatever they are @RYANTADIPARTHI
Do you advice me to make the numbers [email protected]
@SaraAlsa yes sure.
Write a program that creates an array of integers that stores the following values: 45,78, 12, 67, 55, 89, 23, 77, 88
Print only values that stored with even index including 0.