0

(Solved) Help in this code

//this is the code package com.randpkg.afsc; import java.util.Scanner; public class defaultiii { public static void rand (){ double randDouble = Math.random (); randDouble = randDouble * 100; int randInt = (int) randDouble; System.out.println("Did yiu had "+randInt+" in the test?"); } public static void main(String[] args) { String nop = "n" ; rand(); Scanner answer = new Scanner (System.in); String ans = answer.nextLine(); if (ans=="n") { rand (); }else { System.out.println("I knew it!"); }; } } /* Help me, this isn't working, why? * == random number (0/100) (OUTPUT): Did you had * in the test? (INPUT): n (OUTPUT): I knew it (END) i want to code this program for it try to ask if i had * in the test all the times i input 'n' https://code.sololearn.com/c50DaGd0vPij/?ref=app

27th Jun 2018, 10:13 AM
Afsc19
Afsc19 - avatar
7 Answers
+ 1
the prolem is that it the if statment isn't working, only the else works
27th Jun 2018, 10:38 AM
Afsc19
Afsc19 - avatar
+ 1
WORKED, THANKYOU!!
27th Jun 2018, 10:43 AM
Afsc19
Afsc19 - avatar
0
before the if statment?
27th Jun 2018, 10:40 AM
Afsc19
Afsc19 - avatar
0
ok trying it
27th Jun 2018, 10:41 AM
Afsc19
Afsc19 - avatar