Symbianize Forum

Most of our features and services are available only to members, so we encourage you to login or register a new account. Registration is free, fast and simple. You only need to provide a valid email. Being a member you'll gain access to all member forums and features, post a message to ask question or provide answer, and share or find resources related to mobile phones, tablets, computers, game consoles, and multimedia.

All that and more, so what are you waiting for, click the register button and join us now! Ito ang website na ginawa ng pinoy para sa pinoy!

JAVA help... last digit minus remaining numbers

jhunnx

Apprentice
Advanced Member
Messages
86
Reaction score
0
Points
26
May pinapagawa po samin prof namin medyo mahirap po.
Kapag nag input ka po ng numbers ex. "1234'"
Yung last number na 4 dapat po maminus po sya sa remaining numbers na "123"
Parang ganito po 123-5=118
118 po dapat ang output. Patulong naman po ty :pray:
 
Try mo ito. Di ako ganun kagaling mag-program ha (marunong lang). Pero baka makatulong ito sayo kahit na paano. Kung kailangan ng validation (positive or negative numbers, numbers only, etc), ikaw na bahala dun. If-Else ang pwede mong gamitin para dun sakaling kailanganin.

import java.util.Scanner;

class Main {

public static void main(String args[]) {

Scanner input = new Scanner(System.in);

System.out.print("Enter a number: ");
int myInput = input.nextInt();

int lastNum, otherNums, diff;

lastNum = myInput % 10;
otherNums = myInput / 10;
diff = otherNums - lastNum;

System.out.print(diff);

}
}
 
Last edited:
Back
Top Bottom