My code is not running | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

My code is not running

5th Feb 2017, 2:14 PM
Syed Kaif
Syed Kaif - avatar
8 Answers
+ 5
@Syed, try the above code. In main(), we call the functions u have defined. As the same variables' instances are used in all the functions, we should declare them as static. With these modifications, this code compiles now.
5th Feb 2017, 4:26 PM
tharun surya dwivedula
tharun surya dwivedula - avatar
+ 1
yes, please share your code and the compiler(IDE) you are using..
5th Feb 2017, 2:45 PM
tharun surya dwivedula
tharun surya dwivedula - avatar
+ 1
I think main () statement is required which is missing in your code..
5th Feb 2017, 2:56 PM
tharun surya dwivedula
tharun surya dwivedula - avatar
+ 1
import java.io.*; class Syed { static String name; static String address; static int phone; static String subject; static float salary; static float tax; public static void inputdata(String n,String a,int p,String s,float sal) { name = n; address = a; phone = p; subject = s; salary = sal; } public static void displaydata() { System.out.println ("==============="); System.out.println("Name="+name); System.out.println("Address="+address); System.out.println("Phone Number="+phone); System.out.println("Subject Specialization="+subject); System.out.println("Monthly Salary="+salary ); } public static void compute() { float totalsal; totalsal=(float)12.0*salary; if(totalsal>175000) { System.out.println("Annual Salary(salary*12)") ; tax=(totalsal-175000)*5/100; System.out.println("Annual Income Tax is="+tax); } else System.out.println("No Tax Amount on this Income:"); } public static void main (String [] args) { inputdata("Syed","address",4608,"Accounts",6 ); displaydata (); compute(); } }
5th Feb 2017, 4:23 PM
tharun surya dwivedula
tharun surya dwivedula - avatar
0
share your code so we can see whats wrong....
5th Feb 2017, 2:21 PM
LordHill
LordHill - avatar
0
import java.io.*; class tax { private String name; private String address; private int phone; private String subject; private float salary; private float tax; public void inputdata(String n,String a,int p,String s,float sal)throws IOException { name = n; address = a; phone = p; subject = s; salary = sal; } void displaydata() { System.out.println ("==============="); System.out.println("Name="+name); System.out.println("Address="+address); System.out.println("Phone Number="+phone); System.out.println("Subject Specialization="+subject); System.out.println("Monthly Salary="+salary ); } public void compute() { float totalsal; totalsal=(float)12.0*salary; if(totalsal>175000) { System.out.println("Annual Salary(salary*12)") ; tax=(totalsal-175000)*5/100; System.out.println("Annual Income Tax is="+tax); } else System.out.println("No Tax Amount on this Income:"); } }
5th Feb 2017, 2:54 PM
Syed Kaif
Syed Kaif - avatar
0
sir please edit
5th Feb 2017, 2:58 PM
Syed Kaif
Syed Kaif - avatar
0
he is right. without a main() your program doesn't have a start
5th Feb 2017, 3:11 PM
LordHill
LordHill - avatar