Results 1 to 10 of 10
Thread: Transmit Int
- 08-18-2011, 01:56 PM #1
Member
- Join Date
- Aug 2011
- Location
- Czech Republic
- Posts
- 12
- Rep Power
- 0
Transmit Int
Hi. My problem is smiling. Ive got 2 file *.class
1st file
2nd fileJava Code:import java.io.IOException; public class Vyber { public static int x; public static void vyber() throws IOException { volba.vyberSi(x); System.out.println(x+" vyber"); switch(x){ case 1: radkove_orientovany_IO.zapisDoSouboru(); case 2: bajtProud.bP(); case 3: znakProud.zP(); case 4: scanner.sc(); case 5: desCarka.dC(); } } }
I dont know how transmit int x. In class volba is x allright, but in class Vyber int x isnt the same number.Java Code:import java.util.*; public class volba { public static int vyberSi(int x){ Scanner sc = new Scanner(System.in); x = sc.nextInt(); System.out.println(x+ " volba"); return x; } }
Thanks for any response.
- 08-18-2011, 02:24 PM #2
The caller of the vyberSi method will receive from that method the value of x. It needs to store what is returned by that method into a local variable. Your code does not store the returned value.
- 08-18-2011, 02:47 PM #3
Member
- Join Date
- Aug 2011
- Location
- Czech Republic
- Posts
- 12
- Rep Power
- 0
Can I ask for writing code, please? I dont know where I have mistake.
- 08-18-2011, 02:52 PM #4
Where is the value of x that you want to be "transmitted"?
From your code. Here is a sample of how you save the value returned by the nextInt() method in x:
x = sc.nextInt();
do the same for your method.
- 08-18-2011, 04:28 PM #5
Member
- Join Date
- Aug 2011
- Location
- Czech Republic
- Posts
- 12
- Rep Power
- 0
Ooops
... Thanks for reaction. Now I know wheres problem but I dont know how write that :-X.
- 08-18-2011, 04:36 PM #6
Please explain what you are trying to do?but I dont know how write that
Where is the value of x that you want to be "transmitted"?
- 08-18-2011, 05:06 PM #7
Member
- Join Date
- Aug 2011
- Location
- Czech Republic
- Posts
- 12
- Rep Power
- 0
I want enter number (x) from class volba to class Vyber, where is Switch (Vyber). I want make a little menu. I can do it in one class, but I want to work with parameter passing.
PS: Sorry for my (little) bad english
- 08-18-2011, 05:10 PM #8
What does your vyberSi method do? Does it return the value of x that you want?number (x) from class volba to class Vyber
You Call that method from the Vyber class to get the value of x.
What does this line do? It calls the vyberSi method but does NOT save the returned value.
volba.vyberSi(x);
- 08-18-2011, 05:16 PM #9
Member
- Join Date
- Aug 2011
- Posts
- 95
- Rep Power
- 0
I think that the point of confusion is...
- Java does "pass by value."
This means that volba can't change the value of the caller's variable 'x'. The 'x' in volba has nothing to do with the 'x' in Vyber. The two are not connected. Changing one does not change the other.
So Vyber needs to do this:
Once that works, some of the other things the code does (which do not help) could be cleaned out.Java Code:x = volba.vyberSi(x);
- 08-18-2011, 05:30 PM #10
Member
- Join Date
- Aug 2011
- Location
- Czech Republic
- Posts
- 12
- Rep Power
- 0
Similar Threads
-
how to transmit image file through USB communicaion
By santhosh_el in forum NetBeansReplies: 0Last Post: 03-28-2009, 07:40 AM -
how to transmit image file through USB communicaion
By santhosh_el in forum NetBeansReplies: 1Last Post: 03-28-2009, 05:28 AM -
How to Transmit data from one node to another
By swimberl in forum NetworkingReplies: 2Last Post: 01-04-2008, 08:48 PM -
How would I transmit my password through java
By silvia in forum NetworkingReplies: 1Last Post: 07-30-2007, 07:29 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks