What's new

Closed I need help again sa java

Status
Not open for further replies.

jayjay12

Addict
Joined
Jun 13, 2015
Posts
274
Reaction
26
Points
122
Age
25
example meron ako dalwang jtextfield ang variable test1 at test2
example nag insert ako sa text1 ng "pogi"
sa test2 naman ang inisert ko "ako"
balak ko sana kuhanin yung pang huli letter kaso diko alam yung logic kung paano kuhanin yung huli
dapat ang kukuhanin ko sa test1 yung "gi" at sa test2 "ko" at pagsasamahin ko sya dapat ang output "giko" tnx for answer netbeans ang gamit ko at java
 
See this example ... :)

public class MyClass {
public static void main(String args[]) {

String txtbox1 = "Pogi"; // example nakuha natin ang data from the textbox
String txtbox2 = "Lodi"; // example nakuha natin ang data from the textbox

// gamit ka po ng substring na function... You do not have permission to view the full content of this post. Log in or register now.
// substring usage = [stringToCut](.)substring([starting_index],[ending_index])
// bale ang ginawa po natin dito is kunin natin ang total length ng characters ng first textbox
// so let us say Pogi = 4 characters
// since ang kukunin po natin is ang last two letters na 'GI'
// ang last letter 'I' ay nasa index 4 : then ang letter 'G' ay nasa index number 3
// ang gagawin po natin is using the predefined function [length()] = calculates the total number of characters in a string
// txtbox1.length() = 4 minus tayo ng two so equals 2...
// so parang in short ... txtbox1.substring(2,4) now bakit sa 2 ang start? since magsstart siya ng count sa in between
// ng starting index and ending index so basically ang kukunin niya na ang 3rd and 4th character talaga...
String txtbox1Last = txtbox1.substring(txtbox1.length() - 2,txtbox1.length());

// same process talaga
String txtbox2Last = txtbox2.substring(txtbox2.length()-2,txtbox2.length());

// concatenate ang two results...
String result = txtbox1Last + txtbox2Last;

// print result...
System.out.println(result);

// naalala ko pa kahit papaano mga java days.. :)

}
}
 
Last edited by a moderator:
Status
Not open for further replies.

Similar threads

Back
Top