• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Help With Bluej

Shahr

Junior Member
Hi! my name is Shahr and im using bluej, For Some Reason My Code Isnt Working Properly
import java.util.Scanner;
public class Katan
{
public static void main(String[]args)
{
Scanner in=new Scanner(System.in);
int n,i,math=1;
System.out.println("Enter N");
n=in.nextInt();
for(i=0;i<=1;i++)
{
if(n<10)
{
math=math*n;
System.out.println("Enter N");
n=in.nextInt();
}
else
{
System.out.println("Enter N");
n=in.nextInt();
}
}
System.out.println(math);
}
}
Here Is My Code And Its Supposedly Needs To Print Out Enter N Once And For Some Reason It Prints It 3 Times And Gives The User 3 Time To Enter The Number Again
import java.util.Random;
public class SheshBesh
{
public static void main(String[]args)
{
Random in=new Random();
int Cube1,Cube2,Benim;
Cube1=in.nextInt(6)+1;
Cube2=in.nextInt(6)+1;
while(Cube1!= 5&&Cube2!=6)
{
if(Cube1==6&&Cube2==5)
{
Benim=Cube2;
Cube2=Cube1;
Cube1=Benim;
}
else
{
System.out.println("Cube1= " + Cube1);
System.out.println("Cube2= " + Cube2);
}
Cube1=in.nextInt(6)+1;
Cube2=in.nextInt(6)+1;
}
System.out.println("שש בש");
System.out.println("Cube1= " + Cube1);
System.out.println("Cube2= " + Cube2);
}
}

This Is Another Example Of It Not Working Well. This Code Is Simulating A Cube And Pasting Its Results Until The Cubes Are Either 6 5 Or 5 6, And For Some Reason It Doesnt Count The && And When One Of The Cubes Equals 6 or 5 It Is Ending The Loop, Is It Me? Or Bluej 😛
 
First, use code tags!
Java:
import java.util.Scanner;
public class Katan
{
    public static void main(String[]args)
    {
        Scanner in=new Scanner(System.in);
        int n,i,math=1;
        System.out.println("Enter N");
        n=in.nextInt();
        for(i=0;i<=1;i++)
        {
            if(n<10)
            {
                math=math*n;
                System.out.println("Enter N");
                n=in.nextInt();
            }
            else
            {
                System.out.println("Enter N");
                n=in.nextInt();
            }
        }
        System.out.println(math);
    }
}
Here Is My Code And Its Supposedly Needs To Print Out Enter N Once And For Some Reason It Prints It 3 Times And Gives The User 3 Time To Enter The Number Again

I'm pretty sure your bug is in the first section there. in.nextInt() asks for a value every time it's called. Can you step through the code and see how it's called three times? If not, BlueJ should have a debugger that can step through the code for you from the point where you set a breakpoint.

Another option might be
to change your System.out.println values so each one is unique so you know where calls are being made from.
But that might be giving away too much. 😉
 
Back
Top