pass value inside method A to method B
I'm develop an CLI apps using java.. because i want t0 learn java.
here my snippet:
Code:
import java.io.*;
import java.lang.*;
class Projek
{
public static void main (String args[] )throws IOException
{
int menus;
String input;
BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
{
Projek Mas = new Projek(); //
for (int Ulang = 1; Ulang == 1;)
{
Mas.Arahan(); //<--- calling the function
System.out.print(" \t\t-1 timetable \n \t\t-2 Buy ticket \n \t\t-3 pay ticket\n");
System.out.print("\n # You choose \t\t: ");
input = stdin.readLine();
while(isIntNumber(input)==false) // <--- Error handling (alert user when insert CHAR)
{
System.out.println("\n Opss, wrong input");
System.out.print("\n # You choose \t\t: ");
input = stdin.readLine();
}
menus = Integer.parseInt(input);
Mas.Menu(menus);
System.out.print("\n # continuegi? ( 1= yes / 2= no ) : ");
Ulang = Integer.parseInt(stdin.readLine());
if ( Ulang == 2)
System.out.println(" * Bye *");
}
}
}
static void Arahan()
{
System.out.println(" ======================");
System.out.println(" => menu : ");
System.out.println(" ======================");
}
static void Menu(int menu) // <-- pass the value into functiom
{
if(menu == 1)
Jadual();
else if(menu == 2)
System.out.println(" 2");
else if(menu == 3)
System.out.println(" 3");
else
System.out.print(" err0r weeeh!");
}
static void Jadual()
{
System.out.println("\t\t\t=========================================================================================");
System.out.print("\t\t\t========= \t================\t====================\t=========================");
System.out.println("\n\t\t\t KOD\t\t MASA\t\t Destinasi\t\t\tHARGA");
System.out.println("\t\t\t========= \t================\t====================\t=========================");
for(int p= 0;p<5;p++)
{
String dest[]={"TERENGGANU ","K.LUMPUR","PASIR MAS","PAHANG ","SEREMBAN"};
String time[]={"06:00PM-08.00AM","06:00PM-06.00AM","08:00AM-08:00PM","06:00PM-07:00PM","06:00PM-05:00AM"};
int price[] = {28,23,40,60,30,15,10,25,30,18};
int u=0;
System.out.println(" ");
System.out.println("\t\t\t=> ("+(p+1)+") - \t"+time[p]+"\t\tJOHOR >>> "+dest[p]+"\tDEWASA:RM"+price[p]+" @ KANAK2:RM"+price[p+5]);
}
System.out.print("\t\t\t========= \t================\t====================\t=========================");
System.out.print("\n\t\t\t=========================================================================================");
}
static boolean isIntNumber(String num) // <-- Error handling
{
try
{
Integer.parseInt(num);
}
catch(NumberFormatException nfe)
{
return false;
}
return true;
}
}
Acctualy this code are more longer.. but i shorted it here.
here.. my quest:
i has main class
Code:
public static void main( String args[])
then i pass a value to a method.. for example, it pass char value X
*Just assume the user has already input the value that declare as LOL.
thus code was insert into main..to pass the value
and..now inside the method is
Code:
getInput(char GEEK)
{
System.out.print("LOL is : "+GEEK);
}
get
Thus code are running without error..but if i pass the value method -> meth0d. sumthing goes wrong....
as snippet:
Code:
getInput(char GEEK)
{
System.out.print("LOL is : "+GEEK);
outInput(char GEEKv2);
}
outInput(char LoL2)
{
System.out.print("GEEK is :" +LoL2);
get
But...i get err0r...
Sorry for long explaination. I post it as the reference to all. maybe someday this thread will help the 0thers.
Anybody can answer this?