JAVA Learning Group
- JustAnyone
- Developer
- Reactions:
- Posts: 3480
- Joined: 23 Jul 2017, 12:45
- Location: Easter Island
- Plugins: Showcase Store
-
Platform
- Lobby
- Developer
- Reactions:
- Posts: 3705
- Joined: 26 Oct 2008, 12:34
- Plugins: Showcase Store
- Version: Beta
-
Platform
Re: JAVA Learning Group
You could simplify your program to
Or short and dirty:
Code: Select all
public class Program {
public static void main(String[] args) {
//by Josh, have a nice day!
int age = 18;
//choose your age
int money = 500;
//choose how much money you have
if (age >= 18 || money >= 500) {
System.out.println("Welcome!");
} else {
System.out.println("Sorry but you are not allowed!");
}
}
}
Code: Select all
public class Program {
public static void main(String[] args) {
//by Josh, have a nice day!
int age = 18;
//choose your age
int money = 500;
//choose how much money you have
System.out.println((age >= 18 || money >= 500) ? "Welcome!" : "Sorry but you are not allowed!");
}
}
- 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
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!");
}
}
}
- 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
Just change the int
To get a different output
Maybe use a Boolean it will make stuff interesting...
To get a different output
Maybe use a Boolean it will make stuff interesting...
- Lobby
- Developer
- Reactions:
- Posts: 3705
- Joined: 26 Oct 2008, 12:34
- Plugins: Showcase Store
- Version: Beta
-
Platform
Re: JAVA Learning Group
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;
}
}
}
}
- JustAnyone
- Developer
- Reactions:
- Posts: 3480
- Joined: 23 Jul 2017, 12:45
- Location: Easter Island
- Plugins: Showcase Store
-
Platform
- 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
Not too hard for me
- Lobby
- Developer
- Reactions:
- Posts: 3705
- Joined: 26 Oct 2008, 12:34
- Plugins: Showcase Store
- Version: Beta
-
Platform
Re: JAVA Learning Group
For common problems like sorting you'll probably find something useful in the default libraries:
The output is [7, 9, 16, 42, 666]
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);
}
}
- 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
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();
}
}
- 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
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);
}
}
- JustAnyone
- Developer
- Reactions:
- Posts: 3480
- Joined: 23 Jul 2017, 12:45
- Location: Easter Island
- Plugins: Showcase Store
-
Platform
Re: JAVA Learning Group
When mini game ends in my app:
Last edited by JustAnyone on 27 Aug 2017, 21:51, edited 1 time in total.
- 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
urmm is that your face?JustAnyone wrote: ↑27 Aug 2017, 01:36When mini game ends in my app:Screenshot_2017-08-27-02-34-13-519_com.justanyone.jasoftware.png
- JustAnyone
- Developer
- Reactions:
- Posts: 3480
- Joined: 23 Jul 2017, 12:45
- Location: Easter Island
- Plugins: Showcase Store
-
Platform
Re: JAVA Learning Group
My friend'sFireout wrote: ↑27 Aug 2017, 08:42urmm is that your face?JustAnyone wrote: ↑27 Aug 2017, 01:36When mini game ends in my app:Screenshot_2017-08-27-02-34-13-519_com.justanyone.jasoftware.png
- 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
and the girl one?JustAnyone wrote: ↑27 Aug 2017, 11:23My friend'sFireout wrote: ↑27 Aug 2017, 08:42urmm is that your face?JustAnyone wrote: ↑27 Aug 2017, 01:36When mini game ends in my app:Screenshot_2017-08-27-02-34-13-519_com.justanyone.jasoftware.png
- JustAnyone
- Developer
- Reactions:
- Posts: 3480
- Joined: 23 Jul 2017, 12:45
- Location: Easter Island
- Plugins: Showcase Store
-
Platform
- JustAnyone
- Developer
- Reactions:
- Posts: 3480
- Joined: 23 Jul 2017, 12:45
- Location: Easter Island
- Plugins: Showcase Store
-
Platform
Re: JAVA Learning Group
Thank God I found crazy bug which froze my phone.JustAnyone wrote: ↑25 Aug 2017, 14:51I will have to test everything in that app to be sure everything works.