What's new

Guys pa help naman po dito badly needed lang.

BATANG Singkit 01

Eternal Poster
Established
Joined
Mar 22, 2022
Posts
493
Reaction
31
Points
439
Guys pede makahingi ng codes dito, using inheritance need ko lang tlga nahihirapan na kasi ako jdoodle lang gamit ko. Salamat mga lods

image-bb7d0342-9807-4a5d-8148-8fe2251ae874.jpg

Eto po yung code ko kaso di ko paalam paano gawin inheritance po ito jdoodle lang po kasi gamit ko.


import java.util.*;


class OutOfRangeException extends Exception{

public OutOfRangeException(){

super("Out of range\nGuess a number from 1 to 50!");

}

}

public class main1{


static void game(int guess, int target){}

public static void main(String args[]){

Scanner sc = new Scanner(System.in);

Random r = new Random();

int target = r.nextInt((50 - 1) + 1) + 1;

int guess = -1;

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

int count=1;

do{

try{

guess = sc.nextInt();

if(guess<1 || guess>50)

throw new OutOfRangeException();

if(guess<target){

System.out.println("Too low. Try again.");

count+=1;

}

if(guess>target){

System.out.println("Too high. Try again.");

count+=1;

}

}

catch(OutOfRangeException e){

System.out.println(e.getMessage());

count+=1;

}

catch(InputMismatchException e){

System.out.println("Invalid Input\nGuess a number from 1 to 50!");

count+=1;

sc.nextLine();

}

}while(guess!=target);

}

}
 

Attachments

Last edited:
Ito yt vid..
https://youtu♠be/zbVAU7lK25Q

Palitan mo ng dot yung ♠
Pwedi kang gumamit ng online compiler para dyan.. Search google..
 

Similar threads

Back
Top