Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[java prob]guna user input dan methode erroe indintifier
19-04-2012, 03:10 PM,
Post: #1
[java prob]guna user input dan methode erroe indintifier
Code:
import java.io.*;
class calculator
{
BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
int a,b;
String c;
System.out.println("masukan nilai a: ");
c=stdin.readLine();
a=Integer.parseInt(c);
System.out.println("masukan nilai b: ");
c=stdin.readLine();
b=Integer.parseInt(c);
void add()
{
System.out.println("hasil tambah dua nilai "+(a+b));
}
public static void main(String[] args) throws IOException
{
calculator c1=new calculator();
c1.add();
}
}
Angry

sharing your knowledge to grow your knowledge...

and the knowledge is life not death
Reply
22-04-2012, 08:47 AM, (This post was last modified: 22-04-2012, 08:48 AM by cupin06.)
Post: #2
RE: [java prob]guna user input dan methode erroe indintifier
PHP Code:
import java.io.*;
class 
calculator{
    
    
int aConvert,bConvert



    
void readInput() throws IOException{
    
    
BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
    
String a,b;

    
System.out.println("masukan nilai a: ");
    
a=stdin.readLine();
    
aConvert=Integer.parseInt(a);
    
System.out.println("masukan nilai b: ");
    
b=stdin.readLine();
    
bConvert=Integer.parseInt(b);
    }
    
void add()
    {
    
System.out.println("hasil tambah dua nilai "+(aConvert+bConvert));
    }
    public static 
void main(String[] argsthrows IOException
    
{
    
calculator c1=new calculator();
    
c1.readInput();
    
c1.add();
    }
    } 

ko nya silap first ko x letak nama method.. ini contoh nama method aku kasi.
Code:
void readInput() throws IOException{

Pastu ko silap declare variable.sepatutnya ko kena set variable tu jd instance variable. Kalo ko x set jd instance variable nnt method void add() x leh nk jumpa ko nye variable.
Code:
int aConvert,bConvert;





[Image: Untitled-1.png]
Reply
22-04-2012, 07:56 PM,
Post: #3
RE: [java prob]guna user input dan methode erroe indintifier
ok thank skrang dah paham
Angry

sharing your knowledge to grow your knowledge...

and the knowledge is life not death
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  Soalan Java darknite 10 805 27-11-2013, 01:47 PM
Last Post: darknite
  soalan java. hard3 4 919 10-05-2013, 10:33 PM
Last Post: JejakaPemalu
  [help] inputfile java please click me to know more Timon 0 394 14-04-2013, 10:02 PM
Last Post: Timon
  [problem]with java tcp client and server chat pron3t 1 555 26-02-2013, 01:21 PM
Last Post: muhaznar
  java API Timon 3 827 09-12-2012, 09:58 PM
Last Post: lamki
  java background music library Timon 0 444 09-12-2012, 05:21 PM
Last Post: Timon
  JAVA Layout... mana 1 feveret :P 127001 7 1,676 03-12-2012, 10:32 AM
Last Post: Wushipher
  [tutorial]constructor methode pron3t 3 759 30-11-2012, 03:21 PM
Last Post: s3m00t
  Java | MS Excell 127001 5 1,040 29-07-2012, 12:41 AM
Last Post: lamki
  Tutorial: Menghubungkan SQLite Dengan Java s3m00t 4 1,290 25-07-2012, 02:40 AM
Last Post: s3m00t

Forum Jump: