#Scanner not responding in loops

5 messages · Page 1 of 1 (latest)

viral ember
#

@dreamy steppe please use #1023632039829831811 and also use syntax highlighting as shown in #❗︱how-to-get-help

dreamy steppe
#

ok

#

public class NinthClassSeventh {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        System.out.println("!!NUMBERS WITH SIGN COUNT!!");
        String c = "Y";
        int p = 0;
        int n = 0;
        int z = 0;

        while(c.equals("Y") || c.equals("y")){
            System.out.print("Number = ");
            float i = sc.nextFloat();
            if (i>0){
                p++;
            }else if (i==0){
                z++;
            }else{
                n++;
            }
            System.out.println("Enter (y) or (Y) to Continue or Anything Else to Stop");
            System.out.print("Response = ");
            String r = sc.nextLine();
            c=r;
        }

        // for( ; ; ){
        //     System.out.print("Number = ");
        //     float i = sc.nextFloat();
        //     if (i>0){
        //         p++;
        //     }else if (i==0){
        //         z++;
        //     }else{
        //         n++;
        //     }
        //     System.out.print("Enter (y) or (Y) to Continue or Anything Else to Stop\nResponse = ");
        //     String r = sc.next();
        //     if (r.equals("y") || r.equals("Y")){
        //     }else{
        //         break;

        //     }
        // }
        System.out.println("Result ->\nPositive Numbers = "+p+"\nNegative Numbers = "+n+"\nZeroes = "+z);


    }
    
}```
viral ember
#

@dreamy steppe please use the channel #1023632039829831811 and also use syntax highlighting as shwon in #❗︱how-to-get-help

#

I will close this post. This is for code review, not java help.