🔒 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
  • 531
    Views
  • 3
    Participants
Last reply from:
Alieson09

Trending Topics

Online now

Members online
450
Guests online
1,933
Total visitors
2,383

Forum statistics

Threads
2,290,569
Posts
29,065,186
Members
1,212,400
Latest member
Ms_Lou07
Back
Top