package com.codegym.task.task02.task0207;
/*
Part of a calculator
*/
public class Solution {
public static void main(String[] args) {
int a=5;
int b=7;//write your code here
sum(5,7);
product(5,7);
}
public static void product(int a,int b)
{
System.out.println(a*b);
}
public static void sum(int a,int b)
{
System.out.println(a+b);
}
}
if i don't use static .What is use of static in method ?
Resolved
Comments (6)
- Popular
- New
- Old
You must be signed in to leave a comment
Lakshmanan Subramanian
22 September 2019, 14:35
I am getting illegal start of expression for the same code
0
Ivanov
16 June 2019, 10:41
Можно написать короче:
int a = 5;
int b = 7;
System.out.println(a + b);
System.out.println(a * b);
0
William Leininger
15 January 2019, 07:37
Please elaborate on your issue/question.
An issue I see is that you're declaring more than two variables which would be a condition failure.
Requirements:
1. The program should display text on the screen.
2. The program should have two int variables a and b.
3. The variables must be immediately assigned values.
4. The main method should display the sum of the variables a and b.
5. The main method should display the product of the variables a and b.
6. Each value should be displayed on a new line.
sooo I tried your code at this point. I was surprised. I didn't get an error that the program declared more than two int variables a and b. I figured that reusing those variables exactly would cause a duplicate issue. I learned something logic wise there so thanks for posting this question.
My advice was going to be to simplify your code to just be the lines inside the code.
Anyways. Please elaborate
fyi Jagadeesh Prasad I was able to successfully verify using any values for the variables as the conditions didn't specify specific values to be used.
+1
Jagadeesh Prasad
10 December 2018, 08:20
change the values to a=3; and b=2;
0
Nikash Sahu
11 October 2018, 18:32solution
if you dont use static then u have to create object of the class and with that object reference u need to call ur specific method from main method.....then ur specified method will execute..but in case of static method u can call it directly or with class name...
+2
Ankush Rajput
9 October 2018, 03:34
Program seems fine. What is the problem? Please explain it more clearly.
+1