❓ Help Java pa help naman

andrwxzy

Enthusiast
PROGRAMMING


Write a Java application that uses the Math class to determine the answers for each of the following:


The larger and the smaller of the character K and the integer 70

A random number between 0 and 10 (Hint: The random() method returns a value between 0 and 1; you want a number that is 10 times larger.)

P.S may iba pang question jan tinanggal ko na since kaya ko naman yan lang talaga dibko maintindihan
Kahit di niyo gawin kahit ipaliwanag niyo lany feel ko kasi di complete yung tanong
Thankyouuu
 
Sure! I can help you with that.

To determine the larger and smaller value between the character 'K' and the integer 70, you can use the Math.max() and Math.min() methods from the Math class.

Here's the code to find the larger value:

Java:
char ch = 'K';
int num = 70;

int largerValue = Math.max(ch, num);
System.out.println("The larger value is: " + largerValue);

And here's the code to find the smaller value:

Java:
char ch = 'K';
int num = 70;

int smallerValue = Math.min(ch, num);
System.out.println("The smaller value is: " + smallerValue);

For the second part of your question, to generate a random number between 0 and 10 (inclusive), you can use the Math.random() method and multiply it by 10. Remember to cast the result to an int if you want an integer value.

Here's the code to generate a random number between 0 and 10:

Java:
double randomNumber = Math.random() * 10;
int randomInt = (int) randomNumber;
System.out.println("Random number between 0 and 10: " + randomInt);

I hope this helps! Let me know if you have any further questions.
 

About this Thread

  • 1
    Replies
  • 624
    Views
  • 1
    Participants
Last reply from:
Unknown user

Trending Topics

Online now

Members online
1,269
Guests online
2,378
Total visitors
3,647

Forum statistics

Threads
2,292,774
Posts
29,079,457
Members
1,209,489
Latest member
xemyxemy2026ab
Back
Top