🔒 Closed JAVA help... last digit minus remaining numbers

Status
Not open for further replies.

k4rm4

Honorary Poster
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);
}
}
 
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.

About this Thread

  • 3
    Replies
  • 520
    Views
  • 4
    Participants
Last reply from:
mrHazan

Trending Topics

Online now

Members online
417
Guests online
2,156
Total visitors
2,573

Forum statistics

Threads
2,291,068
Posts
29,068,395
Members
1,211,680
Latest member
tylr
Back
Top