> Help with parseInt in Java? Fractional Calculator help?

Help with parseInt in Java? Fractional Calculator help?

Posted at: 2014-12-18 
I have some questions

If you wan to calculate fractional Part ,Why you are entering "quit" .

If you want integer input during execution use nextInt in place of nextLine

e.g.

Scanner sc = new Scanner(System.in);

int i = sc.nextInt();

2) The parseInt converts string input to the integer one which is like this

int i=Integer.parseInt("123"); //then i become 123

i=i+1;

System.out.println(i); // output will be 124

Comment if any other issue

Syntax:

All the variant of this method are given below:

static int parseInt(String s)

static int parseInt(String s, int radix)

Parameters:

Here is the detail of parameters:

s -- This is a string representation of decimal.

radix -- This would be used to convert String s into integer.

So I have the following program:

public class fractionalCalculator {

public static void main(String[] args) {

Scanner sc = new Scanner (System.in);

boolean x = true;

while (x == true) {

System.out.print("Enter an expression:");

String userInput = sc.nextLine();

System.out.println(userInput);

if (userInput.equals ("quit")) {

sc.close();

System.out.println("Come back soon!");

x = false;

}

}

}

}

---

With the program, we are supposed to turn the userInput into an integer when able to. However, I am having trouble how to apply parseInt. Can it be like int userInput = Integer.parseInt(//here I don't know what to put);

The overall desired result would be the output saying what is the numerator and what is the denominator (which for now should be 1 or -1 since the only input currently should be integer numbers)

My thoughts tell me that I should be using another if loop that says if userInput = int, but I do not know.