What's new

Closed JAVA help... last digit minus remaining numbers

Status
Not open for further replies.

k4rm4

Eternal Poster
Joined
Dec 1, 2017
Posts
677
Reaction
431
Points
293
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
 
import java.util.*;

class Spoonfed {
public static void main(String spoonfedIsReal[]) {
Scanner get = new Scanner(System.in);
int input = get.nextInt();
int minuend = input / 10;
int subtrahend = input % 10;
int difference = minuend - subtrahend;
System.out.println(difference);
}
}
 
Last edited:
Kung gusto mo makuha logic ng problem mo. Yung above code yung maganda pag-aralan.
Pwede mo rin diretsuhin:

Java:
import java.util.Scanner;

public class MP01 {
    
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        
        int userInput;
        int output;
        
        System.out.print("Input: ");
        userInput = s.nextInt();
        output = (userInput/10) - (userInput%10);
        System.out.println("Result: " + output);
    }   
}
 
Status
Not open for further replies.

Similar threads

Back
Top