Jump to content

<python> <java> uhhh can someone convert this to java?

i got code i need to translate to java, im bad at java, can someone help? 

 

 

age = int(input("Enter your age: "))
if age >= 70:
  print ("you may enter")
elif age >= 18:
	print("do you have a vip pass y/n")
	vip = (input(""))
	if 'y' in vip:
		print("you may enter")
	else:
		print("sorry you must have a pass or be over 70 years old")
else :
	print("sorry you must be at least 18 years old")

@TheCoder2019@RockSolid1106 yea so y'all not allowed to see this post...

|:Insert something funny:|

-----------------

*******

#

Link to comment
https://linustechtips.com/topic/1388545-uhhh-can-someone-convert-this-to-java/
Share on other sites

Link to post
Share on other sites

I dunno Java, but try JavaScript or C

specs

Spoiler

ASRock B650I Lightning WiFi

AMD Ryzen 7 7700X

KLEVV CRAS V RGB (2x16GB) 6000MT/s out of the 7200MT/s I could be running

ASUS RTX 3060 OC (12GB)

Thermalright Frozen Edge 240 RGB

Lian Li A4-H2O

 

linux packages

Spoiler

tmux

btop

git

Link to post
Share on other sites

Just now, adarw said:

i need java. homework

My advice is to watch some tutorials for a basic understanding and then ask when you get the basics down

specs

Spoiler

ASRock B650I Lightning WiFi

AMD Ryzen 7 7700X

KLEVV CRAS V RGB (2x16GB) 6000MT/s out of the 7200MT/s I could be running

ASUS RTX 3060 OC (12GB)

Thermalright Frozen Edge 240 RGB

Lian Li A4-H2O

 

linux packages

Spoiler

tmux

btop

git

Link to post
Share on other sites

Just now, TheCoder2019 said:

My advice is to watch some tutorials for a basic understanding and then ask when you get the basics down

ive tried learning java but i hate it. im going to learn it at some point but right now i want to focus on python and c

|:Insert something funny:|

-----------------

*******

#

Link to post
Share on other sites

11 minutes ago, adarw said:

ive tried learning java but i hate it.

 

11 minutes ago, adarw said:

i want to focus on python and c

This is why people should not start with Python.

 

Python is structurally strict and Java is logically based. If you learned Java before Python you already have the logic down, then if you learned Python first, you will be soo focused on structurally basing everything.

 

This is a mistake @RockSolid1106 and I made when switching our Discord bots to JavaScript from Python. We both hated learning and working with JS

specs

Spoiler

ASRock B650I Lightning WiFi

AMD Ryzen 7 7700X

KLEVV CRAS V RGB (2x16GB) 6000MT/s out of the 7200MT/s I could be running

ASUS RTX 3060 OC (12GB)

Thermalright Frozen Edge 240 RGB

Lian Li A4-H2O

 

linux packages

Spoiler

tmux

btop

git

Link to post
Share on other sites

13 minutes ago, adarw said:

i got code i need to translate to java, im bad at java, can someone help? 

 

 

age = int(input("Enter your age: "))
if age >= 70:
  print ("you may enter")
elif age >= 18:
	print("do you have a vip pass y/n")
	vip = (input(""))
	if 'y' in vip:
		print("you may enter")
	else:
		print("sorry you must have a pass or be over 70 years old")
else :
	print("sorry you must be at least 18 years old")

@TheCoder2019@RockSolid1106 yea so y'all not allowed to see this post...

Hopefully this can get you started as it seems the only hurdle you'll have is handling text input. The rest should be pretty straight forward for you. Give it a shot. 

 

https://www.javatpoint.com/how-to-take-string-input-in-java

Intel® Core™ i7-12700 | GIGABYTE B660 AORUS MASTER DDR4 | Gigabyte Radeon™ RX 6650 XT Gaming OC | 32GB Corsair Vengeance® RGB Pro SL DDR4 | Samsung 990 Pro 1TB | WD Green 1.5TB | Windows 11 Pro | NZXT H510 Flow White
Sony MDR-V250 | GNT-500 | Logitech G610 Orion Brown | Logitech G402 | Samsung C27JG5 | ASUS ProArt PA238QR
iPhone 12 Mini (iOS 18.3) | iPhone 15 (iOS 18.3.1) | KZ AZ09 Pro x KZ ZSN Pro X | Sennheiser HD450bt
Intel® Core™ i7-1265U | Kioxia KBG50ZNV512G | 16GB DDR4 | Windows 11 Enterprise | HP EliteBook 650 G9
Intel® Core™ i5-8520U | WD Blue M.2 250GB | 1TB Seagate FireCuda | 16GB DDR4 | Windows 11 Home | ASUS Vivobook 15 
Intel® Core™ i7-3520M | GT 630M | 16 GB Corsair Vengeance® DDR3 |
Samsung 850 EVO 250GB | macOS Catalina | Lenovo IdeaPad P580

Link to post
Share on other sites

13 minutes ago, TheCoder2019 said:

This is a mistake @RockSolid1106 and I made when switching our Discord bots to JavaScript from Python. We both hated learning and working with JS

Well I do like JS a bit now, seems I understand the basics.

 

@adarw you can use Scanner in Java to take input. Import that by

import java.util.Scanner;

Then create an object of Scanner:

Scanner sc = new Scanner(System.in);

You've now created an object. I'd advise you to understand how objects work if you want to understand what this means. 

 

You can take input in various data types like double, float, int, String:

String s = sc.next(); //You'll only need this and int if you're just understanding the very basics.
int s = sc.nextInt(); //this^^
double n = sc.nextDouble();
float f = sc.nextFloat()

 

A sample program:

import java.util.Scanner;

public class rock {
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    System.out.println("Hey, enter your name!");
    String name = sc.next();
    System.out.println("Enter your age: ");
    int age = sc.nextInt();
    System.out.println("Hey there "+name+", I now know that you're "+age+"!");
  }
}

 

 

Hope this helps.

 

Thankfully the Java shit taught to me at school comes to use.

On 4/5/2024 at 10:13 PM, LAwLz said:

I am getting pretty fucking sick and tired of the "watch something else" responses. It's such a cop out answer because you could say that about basically anything, and it doesn't address the actual complaints. People use it as some kind of card they pull when they can't actually respond to the criticism raised but they still feel like they need to defend some company/person. If you don't like this thread then stop reading it. See how stupid it is? It's basically like telling someone "shut the fuck up". It's not a clever responsive, it doesn't address anything said, and it is rude. 

 ^

-----

MKBHD is but an Apple propagandist and fanboy. Take his videos with a grain of salt, especially about anything Apple. In his video titled "I Visited Apple's Secret iPhone Testing Labs!", he has shown that he makes no effort to fact check Apple's claims, and takes it at face value. I do not believe he can be trusted as an Reviewer/Influencer.

-----

bruh switch to dark mode its at the bottom of this page

VPN Server Guide

Link to post
Share on other sites

1 hour ago, TheCoder2019 said:

Python is structurally strict and Java is logically based. If you learned Java before Python you already have the logic down, then if you learned Python first, you will be soo focused on structurally basing everything.

 

what do you mean by that?

 

|:Insert something funny:|

-----------------

*******

#

Link to post
Share on other sites

8 minutes ago, adarw said:

what do you mean by that?

 

Python will bitch and yell at you for indentation mistakes

 

Java and a few others don't

specs

Spoiler

ASRock B650I Lightning WiFi

AMD Ryzen 7 7700X

KLEVV CRAS V RGB (2x16GB) 6000MT/s out of the 7200MT/s I could be running

ASUS RTX 3060 OC (12GB)

Thermalright Frozen Edge 240 RGB

Lian Li A4-H2O

 

linux packages

Spoiler

tmux

btop

git

Link to post
Share on other sites

34 minutes ago, TheCoder2019 said:

Python will bitch and yell at you for indentation mistakes

 

Java and a few others don't

no different than forgetting a } somewhere imo.

Community Standards || Tech News Posting Guidelines

---======================================================================---

CPU: R5 9600X || GPU: RX 9070 XT|| Memory: 32GB || Cooler: Peerless Assassin || PSU: RM850e|| Case: Lian Li A3

Link to post
Share on other sites

3 hours ago, adarw said:

i need java. homework

If it's homework, the point is that you should learn how to do this yourself. We can help you if you try it yourself and can't quite understand something specific or are having trouble debugging your code.

2 hours ago, TheCoder2019 said:

Python will bitch and yell at you for indentation mistakes

 

Java and a few others don't

I don't see how this could make you a worse programmer. Poorly indented code is awful and other languages definitely won't yell at you for using proper indentation... as a beginner, one should be more concerned with the logic of what they're typing rather than specific language quirks.

Don't ask to ask, just ask... please 🤨

sudo chmod -R 000 /*

Link to post
Share on other sites

22 hours ago, TheCoder2019 said:

Python will bitch and yell at you for indentation mistakes

 

Java and a few others don't

Gotta love it when some IDEs use tab indentation while others use spaces. Heaven forbid you're doing a group project and up with both in the same file. 

Intel® Core™ i7-12700 | GIGABYTE B660 AORUS MASTER DDR4 | Gigabyte Radeon™ RX 6650 XT Gaming OC | 32GB Corsair Vengeance® RGB Pro SL DDR4 | Samsung 990 Pro 1TB | WD Green 1.5TB | Windows 11 Pro | NZXT H510 Flow White
Sony MDR-V250 | GNT-500 | Logitech G610 Orion Brown | Logitech G402 | Samsung C27JG5 | ASUS ProArt PA238QR
iPhone 12 Mini (iOS 18.3) | iPhone 15 (iOS 18.3.1) | KZ AZ09 Pro x KZ ZSN Pro X | Sennheiser HD450bt
Intel® Core™ i7-1265U | Kioxia KBG50ZNV512G | 16GB DDR4 | Windows 11 Enterprise | HP EliteBook 650 G9
Intel® Core™ i5-8520U | WD Blue M.2 250GB | 1TB Seagate FireCuda | 16GB DDR4 | Windows 11 Home | ASUS Vivobook 15 
Intel® Core™ i7-3520M | GT 630M | 16 GB Corsair Vengeance® DDR3 |
Samsung 850 EVO 250GB | macOS Catalina | Lenovo IdeaPad P580

Link to post
Share on other sites

Hi @adarw

Java solution:
 

import java.util.InputMismatchException;
import java.util.Scanner;

public class Application {

    public static void main (String [] args) {
        // Initialize scanner, similar to input in python
        Scanner sc = new Scanner(System.in);

        // Age variable
        int age = -1;

        // Run while loop until we have a valid age
        while (age == -1) {
            try {
                System.out.print("Enter your age: ");
                age = sc.nextInt();
            } catch (InputMismatchException e) {
                System.out.println("That is not a number");
                
                // Clear the previous value
                sc.next();
            }
        }

        if (age >= 70) {
            System.out.println("You may enter");
        } else if (age >= 18) {
            System.out.print("Do you have a VIP pass? (y/n): ");
            String vipPass = sc.next();

            if (vipPass.equalsIgnoreCase("y")) {
                System.out.println("You may enter");
            } else {
                System.out.println("Sorry you must have a pass or be over 70 years old");
            }
        } else {
            System.out.println("Sorry you must be at least 18 years old");
        }
    }
}

 

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×