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 I need help again sa java

jayjay12

Addict
Joined
Jun 13, 2015
Messages
274
Reaction
26
Age
22
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:
Comment

Online statistics

Members online
1,097
Guests online
1,872
Total visitors
2,969

Forum statistics

Threads
1,074,363
Messages
18,147,034
Members
1,517,237
Comments
1,098,293
Attachments
1,393,828
Profile posts
97,644
Top