Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7720863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:46:35+00:00 2026-06-01T03:46:35+00:00

I need to retrieve out the nominator and denominator into two int type variables,

  • 0

I need to retrieve out the nominator and denominator into two int type variables, from a string. It could be:
"1/-2", "4 /0", "-2/ 1234", or " 5"(in this case the denominator is 1);

There might be spaces between the integers and "/", no spaces inside a integer.
And there might be only one integer in the string and no "/".

Any ideas? Thanks.

Hi, I combined your guys’ answers, and it works! Thanks!

s is the string

s = s.trim();
String[] tokens = s.split("[ /]+");
int inputNumerator = Integer.parseInt(tokens[0]);
int inputDenominator = 1;
if (tokens.length != 1)
    inputDenominator = Integer.parseInt(tokens[1]);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T03:46:37+00:00Added an answer on June 1, 2026 at 3:46 am
    String[] parts = s.split(" */ *");
    int num = Integer.parseInt(parts[0]),
        den = Integer.parseInt(parts[1]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to retrieve information from two separate models which are similar but not
I need to retrieve all items from two lists that contains a given value.
I need to retrieve fields from all related records into a parent entity. I
Hi I'm new to Oracle 10g. I need retrieve the all the sublist from
I need to retrieve a value from a website (can vary and I have
i need to retrieve the page title from an URL i already have using
I need to retrieve random rows from SQL Server database. I am looking for
I need to retrieve the date from a UIDatePicker (Preferably I would also like
I need to retrieve multiple objects from an external system. The external system supports
I am trying to figure out how to retrieve data from a MySQL database

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.