JAVA Learning Group

Here you can talk about everything you want.
User avatar
Josh
Graphic designer
Reactions:
Posts: 2214
Joined: 11 Mar 2017, 19:20
Location: The Netherlands
Plugins: Showcase Store
Version: Beta

Plugin Creator

Platform

Re: JAVA Learning Group

#26

Post by Josh »

I added an input, here is your small game :)

Code: Select all

public class Main
{
	public static void main(String[] args)
	{
		System.out.println("Hello World!");

		Scanner input = new Scanner(System.in);

		System.out.print("What is your age?: ");
		double age = input.nextDouble();

		System.out.print("How much money do you have?: ");
		double money = input.nextDouble();

		if (age >= 18 || money >= 500) {
            System.out.println("Welcome!");
        } else {
            System.out.println("Sorry but you are not allowed!");
        }        
    }
		}
	

User avatar
Bearbear76
Former Bearbear65
Reactions:
Posts: 5730
Joined: 10 Feb 2017, 14:53
Location: L2 cache
Plugins: Showcase Store

Plugin Creator

Platform

Re: JAVA Learning Group

#27

Post by Bearbear76 »

Just change the int
To get a different output

Maybe use a Boolean it will make stuff interesting...

User avatar
Lobby
Developer
Reactions:
Posts: 3705
Joined: 26 Oct 2008, 12:34
Plugins: Showcase Store
Version: Beta

Platform

Re: JAVA Learning Group

#28

Post by Lobby »

Code: Select all

import java.util.Random;
import java.util.Scanner;

public class Guess {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Random rnd = new Random();
        int chosenNumber = rnd.nextInt(100);

        System.out.println("I just chose a number between 0 and 99. Please guess it.");

        while (true) {
            System.out.print("Enter your guess: ");
            int guess = scanner.nextInt();

            if (guess < chosenNumber) {
                System.out.println("The chosen number is greater than that");
            } else if (guess > chosenNumber) {
                System.out.println("The chosen number is smaller than that");
            } else {
                System.out.println("Congratulations, the chosen number is indeed " + chosenNumber);
                break;
            }
        }
    }
}

User avatar
Luigi
Inhabitant of a Planet
Reactions:
Posts: 1457
Joined: 17 Mar 2017, 11:25
Location: Fairview Coast
Plugins: Showcase Store

Platform

Re: JAVA Learning Group

#29

Post by Luigi »

Too much to take!

User avatar
JustAnyone
Developer
Reactions:
Posts: 3470
Joined: 23 Jul 2017, 12:45
Location: Easter Island
Plugins: Showcase Store

Platform

Re: JAVA Learning Group

#30

Post by JustAnyone »

Luigi wrote:
26 Aug 2017, 13:28
Too much to take!
Yea at beginning of coding my brain was melting too.

User avatar
Bearbear76
Former Bearbear65
Reactions:
Posts: 5730
Joined: 10 Feb 2017, 14:53
Location: L2 cache
Plugins: Showcase Store

Plugin Creator

Platform

Re: JAVA Learning Group

#31

Post by Bearbear76 »

Not too hard for me

User avatar
Lobby
Developer
Reactions:
Posts: 3705
Joined: 26 Oct 2008, 12:34
Plugins: Showcase Store
Version: Beta

Platform

Re: JAVA Learning Group

#32

Post by Lobby »

For common problems like sorting you'll probably find something useful in the default libraries:

Code: Select all

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Sort {
    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();
        list.add(42);
        list.add(9);
        list.add(7);
        list.add(16);
        list.add(666);

        Collections.sort(list);

        System.out.println(list);
    }
}
The output is [7, 9, 16, 42, 666]

User avatar
Josh
Graphic designer
Reactions:
Posts: 2214
Joined: 11 Mar 2017, 19:20
Location: The Netherlands
Plugins: Showcase Store
Version: Beta

Plugin Creator

Platform

Re: JAVA Learning Group

#33

Post by Josh »

This code creates a random password :)

Code: Select all

import java.net.*;
import java.util.*;

public class Josh
{
    public static void main(String[] args) {
        System.out.println(test(10));
    }
    
    public static String test(int len){
    
    String chars = "0123456789QWERTYUIOPASDFGHJKLZXCVBNMqwettyuiopasdfghjklzxcvbnm";
    StringBuilder sb = new StringBuilder();
    for(int i = 0; i < len;i++){
        sb.append(chars.charAt(new Random().nextInt(59)));
    }
        return sb.toString();
    }
 }

User avatar
Josh
Graphic designer
Reactions:
Posts: 2214
Joined: 11 Mar 2017, 19:20
Location: The Netherlands
Plugins: Showcase Store
Version: Beta

Plugin Creator

Platform

Re: JAVA Learning Group

#34

Post by Josh »

This code calculates which year you are born

Code: Select all

import java.util.Scanner;

public class Josh
{
    public static void main(String [] args) { 
    
        Scanner sc = new Scanner(System.in);
        int age = sc.nextInt();
        int ano = 2017;
        System.out.println("You are born in:");
        System.out.println(ano - age);
  }
}

User avatar
JustAnyone
Developer
Reactions:
Posts: 3470
Joined: 23 Jul 2017, 12:45
Location: Easter Island
Plugins: Showcase Store

Platform

Re: JAVA Learning Group

#35

Post by JustAnyone »

When mini game ends in my app:
Screenshot_2017-08-27-02-34-13-519_com.justanyone.jasoftware.png
Last edited by JustAnyone on 27 Aug 2017, 21:51, edited 1 time in total.

User avatar
malsa
Inhabitant of a Multiverse
Reactions:
Posts: 5085
Joined: 10 Feb 2017, 17:40
Location: Malaysia
Plugins: Showcase Store
Version: Beta

Platform

Re: JAVA Learning Group

#36

Post by malsa »

JustAnyone wrote:
27 Aug 2017, 01:36
When mini game ends in my app:Screenshot_2017-08-27-02-34-13-519_com.justanyone.jasoftware.png
urmm is that your face?

User avatar
JustAnyone
Developer
Reactions:
Posts: 3470
Joined: 23 Jul 2017, 12:45
Location: Easter Island
Plugins: Showcase Store

Platform

Re: JAVA Learning Group

#37

Post by JustAnyone »

Fireout wrote:
27 Aug 2017, 08:42
JustAnyone wrote:
27 Aug 2017, 01:36
When mini game ends in my app:Screenshot_2017-08-27-02-34-13-519_com.justanyone.jasoftware.png
urmm is that your face?
My friend's

User avatar
malsa
Inhabitant of a Multiverse
Reactions:
Posts: 5085
Joined: 10 Feb 2017, 17:40
Location: Malaysia
Plugins: Showcase Store
Version: Beta

Platform

Re: JAVA Learning Group

#38

Post by malsa »

JustAnyone wrote:
27 Aug 2017, 11:23
Fireout wrote:
27 Aug 2017, 08:42
JustAnyone wrote:
27 Aug 2017, 01:36
When mini game ends in my app:Screenshot_2017-08-27-02-34-13-519_com.justanyone.jasoftware.png
urmm is that your face?
My friend's
and the girl one?

User avatar
JustAnyone
Developer
Reactions:
Posts: 3470
Joined: 23 Jul 2017, 12:45
Location: Easter Island
Plugins: Showcase Store

Platform

Re: JAVA Learning Group

#39

Post by JustAnyone »

Fireout wrote:
27 Aug 2017, 11:58
JustAnyone wrote:
27 Aug 2017, 11:23
Fireout wrote:
27 Aug 2017, 08:42
urmm is that your face?
My friend's
and the girl one?
My sister :D

User avatar
JustAnyone
Developer
Reactions:
Posts: 3470
Joined: 23 Jul 2017, 12:45
Location: Easter Island
Plugins: Showcase Store

Platform

Re: JAVA Learning Group

#40

Post by JustAnyone »

JustAnyone wrote:
25 Aug 2017, 14:51
I will have to test everything in that app to be sure everything works.
Thank God I found crazy bug which froze my phone.

User avatar
JustAnyone
Developer
Reactions:
Posts: 3470
Joined: 23 Jul 2017, 12:45
Location: Easter Island
Plugins: Showcase Store

Platform

Re: JAVA Learning Group

#41

Post by JustAnyone »

Finally I give you 1.0.9 Beta version of my app!
Say what you think.
If you have any suggestions, there is feedback button in about section. Thank you Lobby for permission to upload my app.
https://drive.google.com/file/d/0B32tv5 ... p=drivesdk

User avatar
CommanderABab
AB
Reactions:
Posts: 11080
Joined: 07 Jun 2016, 21:12
Plugins: Showcase Store
Version: Beta

Plugin Creator

Platform

Re: JAVA Learning Group

#42

Post by CommanderABab »

Everything tends to open json genie

User avatar
Josh
Graphic designer
Reactions:
Posts: 2214
Joined: 11 Mar 2017, 19:20
Location: The Netherlands
Plugins: Showcase Store
Version: Beta

Plugin Creator

Platform

Re: JAVA Learning Group

#43

Post by Josh »

I can't download it

User avatar
CommanderABab
AB
Reactions:
Posts: 11080
Joined: 07 Jun 2016, 21:12
Plugins: Showcase Store
Version: Beta

Plugin Creator

Platform

Re: JAVA Learning Group

#44

Post by CommanderABab »

Yeah, you have to disable security temporarily. And have an apk installer.

User avatar
JustAnyone
Developer
Reactions:
Posts: 3470
Joined: 23 Jul 2017, 12:45
Location: Easter Island
Plugins: Showcase Store

Platform

Re: JAVA Learning Group

#45

Post by JustAnyone »

Josh wrote:
27 Aug 2017, 21:41
I can't download it
What's wrong?

Locked Previous topicNext topic

Return to “Smalltalk”