Skip to content
Sign upLog in
← Back to Community

java code

Profile icon
SaraAlsa

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

Voters
Profile icon
rhizlanebezaid1
Profile icon
SaraAlsa
Comments
hotnewtop
Profile icon
SayedZ

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.

Profile icon
DynamicSquid

Do you mean this:

class Main { public static void main(String[] args) { OtherClass.someFunction(); } } class OtherClass { // make sure it's static! static void someFunction() { } }
Profile icon
SaraAlsa

Yes also this I have triple using [email protected]

Profile icon
DynamicSquid

@SaraAlsa
Yeah, so just do that

Profile icon
SaraAlsa

can you join to see the problem in calling the function

@DynamicSquid

Profile icon
SaraAlsa

@RYANTADIPARTHI
(1083) OK BUT how can I call them in main
I want them out the main class

Profile icon
Coder100

then put them in main

@SaraAlsa

Profile icon
RYANTADIPARTHI

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.

Profile icon
SaraAlsa

@RYANTADIPARTHI
also I want from the user to enter number and the user maybe enter integer or float

Profile icon
RYANTADIPARTHI

@SaraAlsa
yeah, if you want that, you can just put a int, or float method around it.

Profile icon
SaraAlsa

How can you show me exactly [email protected]

Profile icon
RYANTADIPARTHI

@SaraAlsa
wherever you see the nextInt() in my code i gave you. Just change it to whatever you want like float, and str.

Profile icon
SaraAlsa

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

Profile icon
SaraAlsa

Do you advice me to make the numbers [email protected]

Profile icon
RYANTADIPARTHI

@SaraAlsa
yes sure.

Profile icon
SaraAlsa