Jump to content

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

adarw

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
Share on other sites

Link to post
Share on other sites

I dunno Java, but try JavaScript or C

As Someone with the username “</TheCoder2019_”, my coding skills are atrocious.

Here are my specs:

Spoiler

 

MSI PRO-VLH H310M

Intel Core i3-8100 (Thanks, @Schnoz!)

GTX 1060 OC 3GB or Intel UHD 630

16GB (2x8) Cosair Vengeance LPX CL16 - 2400MHz

GAMDIAS Argus M1

 

An old friend of mine - Intel stock cooler (temps through the roof like 60 C under load)

 

 

Linux Apps you NEED!

Spoiler

tmux

dhcpd

git

 

 


 

 

 

 

 

 

 

Hi! I love RGB! Who doesn't? Karens that don't have colorful lights on their Facebook page

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, TheCoder2019 said:

I dunno Java, but try JavaScript or C

i need java. homework

|:Insert something funny:|

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

*******

#

Link to comment
Share on other sites

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

As Someone with the username “</TheCoder2019_”, my coding skills are atrocious.

Here are my specs:

Spoiler

 

MSI PRO-VLH H310M

Intel Core i3-8100 (Thanks, @Schnoz!)

GTX 1060 OC 3GB or Intel UHD 630

16GB (2x8) Cosair Vengeance LPX CL16 - 2400MHz

GAMDIAS Argus M1

 

An old friend of mine - Intel stock cooler (temps through the roof like 60 C under load)

 

 

Linux Apps you NEED!

Spoiler

tmux

dhcpd

git

 

 


 

 

 

 

 

 

 

Hi! I love RGB! Who doesn't? Karens that don't have colorful lights on their Facebook page

Link to comment
Share on other sites

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 comment
Share on other sites

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

As Someone with the username “</TheCoder2019_”, my coding skills are atrocious.

Here are my specs:

Spoiler

 

MSI PRO-VLH H310M

Intel Core i3-8100 (Thanks, @Schnoz!)

GTX 1060 OC 3GB or Intel UHD 630

16GB (2x8) Cosair Vengeance LPX CL16 - 2400MHz

GAMDIAS Argus M1

 

An old friend of mine - Intel stock cooler (temps through the roof like 60 C under load)

 

 

Linux Apps you NEED!

Spoiler

tmux

dhcpd

git

 

 


 

 

 

 

 

 

 

Hi! I love RGB! Who doesn't? Karens that don't have colorful lights on their Facebook page

Link to comment
Share on other sites

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 17.2.1) | iPhone XR (iOS 17.2.1) | iPad Mini (iOS 9.3.5) | 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 comment
Share on other sites

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. 

 ^

 

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

VPN Server Guide

Link to comment
Share on other sites

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 comment
Share on other sites

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

As Someone with the username “</TheCoder2019_”, my coding skills are atrocious.

Here are my specs:

Spoiler

 

MSI PRO-VLH H310M

Intel Core i3-8100 (Thanks, @Schnoz!)

GTX 1060 OC 3GB or Intel UHD 630

16GB (2x8) Cosair Vengeance LPX CL16 - 2400MHz

GAMDIAS Argus M1

 

An old friend of mine - Intel stock cooler (temps through the roof like 60 C under load)

 

 

Linux Apps you NEED!

Spoiler

tmux

dhcpd

git

 

 


 

 

 

 

 

 

 

Hi! I love RGB! Who doesn't? Karens that don't have colorful lights on their Facebook page

Link to comment
Share on other sites

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 3600 || GPU: RTX 3070|| Memory: 32GB @ 3200 || Cooler: Scythe Big Shuriken || PSU: 650W EVGA GM || Case: NR200P

Link to comment
Share on other sites

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 comment
Share on other sites

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 17.2.1) | iPhone XR (iOS 17.2.1) | iPad Mini (iOS 9.3.5) | 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 comment
Share on other sites

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 comment
Share on other sites

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

×