What's new
  • Welcome to PHCorner forums. Take a moment to sign up and gain unlimited access and extra privileges that guests are not entitled to, such as: All that and more! Registration is quick, simple and absolutely free. Join our community today!

Java Calculator android studio

_KaNeKi_

Established
Joined
Jan 15, 2017
Messages
496
Reaction
61
Age
21
Hi. Ask lang po. Hindi ko po kasi mahanap yung error sa code. Working naman yung calculator pero after isang operator nag foforcle close siya. Dito ko po ba ilalagay yung try and catch ?
IMG_20210428_184537.jpg
 

Attachments

kids hindi to FB na gagana ang bumping ng threads using "up". so stop doing it.

show us the error na nakalagay sa logcat
 
Comment

_KaNeKi_

Established
kids hindi to FB na gagana ang bumping ng threads using "up". so stop doing it.

show us the error na nakalagay sa logcat
Sorry po hahahahaha. Yung error po is nagfo force close lang po lang siya pero wala naman pong nakalagay na text.

Bale ganto po mag tatype muna ako ng equation like 1+1 tapos equal then lalabas yung 2. Then pag ni rekta ko pindot agad another operator dun siya nagfoforce close.
 
Comment

_KaNeKi_

Established
Pa
Di ko ma up vid sir. Pero wala siyang nalabas na error message eh,force closed lang talaga yung apps
Parang ganto:
1+1=2+ force close

Pero pag isahang equation lang like:
1+1=2 then clear. Ok naman pag ganyan
 
1 Comment
A
Arjien
Di na ksi sya sakop sa code mo napupunta sya dun sa else statement.
 

_KaNeKi_

Established
A
Arjien
mahirap I diagnose yung error mo. ksi wla kang err code na pinapakita.
yung gumawa kmi nyan with gui gamit namin.

di ako gumamit ng break.

return lng gnamit ko.
after ksi na case pag na reach na nya yung end wla na tlga madagdag jan.

ksi onetime lng pupuntahan ng switch case except nlng kung iloop mo.
 

_KaNeKi_

Established
mahirap I diagnose yung error mo. ksi wla kang err code na pinapakita.
yung gumawa kmi nyan with gui gamit namin.

di ako gumamit ng break.

return lng gnamit ko.
after ksi na case pag na reach na nya yung end wla na tlga madagdag jan.

ksi onetime lng pupuntahan ng switch case except nlng kung iloop mo.
Ok sir. Ty po sa help
 
Comment

_KaNeKi_

Established
mahirap I diagnose yung error mo. ksi wla kang err code na pinapakita.
yung gumawa kmi nyan with gui gamit namin.

di ako gumamit ng break.

return lng gnamit ko.
after ksi na case pag na reach na nya yung end wla na tlga madagdag jan.

ksi onetime lng pupuntahan ng switch case except nlng kung iloop mo.
IMG_20210429_094809.jpg
 

Attachments

Comment

-GM-JohnPaul

Established
package Paul;
import java.util.Scanner;
public class Paul {


static void Calcu(){
System.out.println("WELCOME TO MY CALCULATOR BY: JohnPaul");

Scanner input = new Scanner(System.in);
int ans = 0;

System.out.println(" 1.Addition 2.Subtraction 3.Multiplication 4.Division ");

String operator = input.next();

System.out.println("First number");
int Firstnumber = input.nextInt();

System.out.println("Second number");
int Secondnumber = input.nextInt();

switch(operator){

case "1":
ans = Firstnumber + Secondnumber;
System.out.println(" Answer is: " + ans);
break;

case "+" :
ans = Firstnumber + Secondnumber;
System.out.println(" Answer is: " + ans);
break;

case "2":

ans = Firstnumber - Secondnumber;
System.out.println(" Answer is: " + ans);
break;


case "-" :

ans = Firstnumber - Secondnumber;
System.out.println(" Answer is: " + ans);
break;

case "3":

ans = Firstnumber * Secondnumber;
System.out.println(" Answer is: " + ans);
break;

case "*" :

ans = Firstnumber * Secondnumber;
System.out.println(" Answer is: " + ans);
break;

case "4" :

ans = Firstnumber / Secondnumber;
System.out.println("Answer is:" + ans);

break;

case "/" :

ans = Firstnumber / Secondnumber;
System.out.println("Answer is:" + ans);

break;


default :

System.out.println(" SORRY YOUR CODE IS WRONG PLEASE TRY AGAIN!! ");

Calcu();

}

Options();

}

@SuppressWarnings("fallthrough")
static void Options(){

Scanner men = new Scanner(System.in);

System.out.println("1.New data \n2.Exit");

int opti = men.nextInt();

switch(opti){

case 1 :
Calcu();
case 2 :
System.exit(0);

default :
System.out.println(" SYSTEM ERROR! PLEASE TRY AGAIN! ");
Options();
}
}

public static void main(String[] args) {
Calcu();
}
}







Ikaw na bahala change sa mga code jan para sa file mo goodluck
 
Comment

frxlux

Grasshopper
papano mo nakukuha yung val1 at val2? via textbox/input ba? or isang string sya tapos pinuputol putol mo lang? ayon kase sa error mo hindi maparse ni Double.parse yung string kase pwedeng hindi sya number
 
Comment

Online statistics

Members online
1,682
Guests online
2,156
Total visitors
3,838

Forum statistics

Threads
1,089,978
Messages
18,306,229
Members
1,524,887
Comments
1,187,979
Attachments
1,423,679
Profile posts
97,930
Top