B-Number


This is a companion discussion topic for the original entry at https://toph.co/p/b-number

What’s wrong with my java code??

import java.util.Scanner;

public class Solution {
	public static void main(String[] args) {		
		Scanner scanner = new Scanner(System.in);
		int x = scanner.nextInt(),j=0;
		if(x>=1 && x<=20000) {
			for(int i=1;i<=x;i++) {
				j=scanner.nextInt();
				if(j>=1&&j<=231) {
					System.out.println(j/3+1);
				}
			}
		}
	}
}

@InanClass5 It seems the input specification had the incorrectly formatted constraints. Instead of 2^31, it was being shown was 231.

You can update your Java code to fix this.

Side note: you do not need to check for these constraints in your code when trying to solve them.

Thanks I solved it.

1 Like