Week 1 Exercise 9

91 views
Skip to first unread message

SayedRakib

unread,
Jan 8, 2015, 7:58:23 PM1/8/15
to moo...@googlegroups.com
Hi,

I'm having problems with week 1 exercise 9.

My Code

        Scanner reader = new Scanner(System.in);   
        
        System.out.print("Type a number: ");
        int numb1 =  Integer.parseInt(reader.nextLine());
        System.out.println(numb1);
                
        System.out.print("Type another number: ");
        int numb2 =  Integer.parseInt(reader.nextLine());
        System.out.println(numb2); 
         
        System.out.println("Division: 3 / 2 = " + (double)numb1 / numb2);

TMC Test Result 

FAIL: DividerTest testNegative
String " 3 / 2 = -1.5
" contains wrong formula when user inputted values 3 and -2

What is my mistake here 


Joni

unread,
Jan 9, 2015, 2:57:03 AM1/9/15
to moo...@googlegroups.com
Hi,

User should be able to input any numbers and equation should be formed using those numbers.

Now your System.out.println contains numbers 3 and 2 instead of using variables.

BR
Joni

nietzs...@hotmail.com

unread,
Oct 26, 2017, 9:07:46 PM10/26/17
to mooc.fi
It gave me some trouble to come up with it as well but here is the right line of code for this exercise.

System.out.print("Division: " + (num1) + "/" + (num2) + "=" + (num1/num2));
Reply all
Reply to author
Forward
0 new messages