🔒 Closed Mga lods java help code

Status
Not open for further replies.

Alieson09

Forum Guru
import java.util.Random;
import java.util.*;

public class PartThree
{

public static void main(String args[]){


int wrong = 0; //number of times guessed wrong
int attempts = 0; //total attempts
int keepGoing = 1;

System.out.println("Guess a number between 1 to 50!");
wrong++;
while (keepGoing == 1){
int x = 1;
Random rand = new Random();
int rnd = rand.nextInt(50); //computer's random number
do{
try{
Scanner scan = new Scanner(System.in);
int guessInt = scan.nextInt();

if (guessInt == rnd){
System.out.println("You got in " + wrong + " attempts");
wrong = 0;
}
else if (guessInt < rnd){
System.out.println("Too low. Try again " );
} else if (guessInt > rnd) {
System.out.println("Too high. Try again ");
}

}//try
catch(Exception e){//error handling
System.out.println("Follow the directions!");
}
}while(x == 1);//do (keep looping until directions are followed and x = 2)
} //while
} //method
} //class
1633838046984.webp
bat ganyan lods hindi mabasa ang attempts kung mabasa man 1 nakalagay
 
import java.util.Random;
import java.util.*;

public class PartThree
{

public static void main(String args[]){



int attempts = 0; //total attempts
int keepGoing = 1;

System.out.println("Guess a number between 1 to 50!");

while (keepGoing == 1){
int x = 1;
Random rand = new Random();
int rnd = rand.nextInt(50); //computer's random number
do{
try{
Scanner scan = new Scanner(System.in);
int guessInt = scan.nextInt();
attempts++;
if (guessInt == rnd){
System.out.println("You got in " + attempts + " attempts");
}
else if (guessInt < rnd){
System.out.println("Too low. Try again " );
} else if (guessInt > rnd) {
System.out.println("Too high. Try again ");
}

}//try
catch(Exception e){//error handling
System.out.println("Follow the directions!");
}
}while(x == 1);//do (keep looping until directions are followed and x = 1)
} //while
} //method
} //class
1633838573181.webp

oks na mga lods haahhaa nakuha na
 
import java.util.Random;
import java.util.*;

public class PartThree
{

public static void main(String args[]){



int attempts = 0; //total attempts
int keepGoing = 1;

System.out.println("Guess a number between 1 to 50!");

while (keepGoing == 1){
int x = 1;
Random rand = new Random();
int rnd = rand.nextInt(50); //computer's random number
do{
try{
Scanner scan = new Scanner(System.in);
int guessInt = scan.nextInt();
attempts++;
if (guessInt == rnd){
System.out.println("You got in " + attempts + " attempts");
}
else if (guessInt < rnd){
System.out.println("Too low. Try again " );
} else if (guessInt > rnd) {
System.out.println("Too high. Try again ");
}

}//try
catch(Exception e){//error handling
System.out.println("Follow the directions!");
}
}while(x == 1);//do (keep looping until directions are followed and x = 1)
} //while
} //method
} //class
View attachment 1659880
oks na mga lods haahhaa nakuha na
yung keepgoing variable hanging,
walang termination ang loop, only inputmismatchexception lang yata nakakapagterminate
 
Status
Not open for further replies.

About this Thread

  • 7
    Replies
  • 528
    Views
  • 3
    Participants
Last reply from:
Alieson09

Online now

Members online
1,042
Guests online
688
Total visitors
1,730

Forum statistics

Threads
2,276,966
Posts
28,973,387
Members
1,229,669
Latest member
zeeeee345
Back
Top