http://www.javaassignmenthelp.net/5-most-popular-java-problems-and-solutions/ Are you looking for Java problems and their solutions? You can find it at the link provided
We aren't sure about you, but working with Java 8 made one of the speakers lose all of his hair and the other lose his sleep (or was it the jetlag?). If you still haven't reached the level of Brian Goetz in mastering lambdas and strings, this talk is for you. And if you think you have, we have some bad news for you, you should attend as well.
This talk is a look into some of the surprising performance cases in Java -- with the goal of illustrating a few simple truths about the nature of compilers.
JVM Mechanics: Understanding the JIT's TricksDoug Hawkins
In this talk, we'll walkthrough how the JIT optimizes a piece Java code step-by-step. In doing so, you'll learn some of the amazing feats of optimization that JVMs can perform, but also some surprisingly simple things that prevent your code from running fast.
We aren't sure about you, but working with Java 8 made one of the speakers lose all of his hair and the other lose his sleep (or was it the jetlag?). If you still haven't reached the level of Brian Goetz in mastering lambdas and strings, this talk is for you. And if you think you have, we have some bad news for you, you should attend as well.
This talk is a look into some of the surprising performance cases in Java -- with the goal of illustrating a few simple truths about the nature of compilers.
JVM Mechanics: Understanding the JIT's TricksDoug Hawkins
In this talk, we'll walkthrough how the JIT optimizes a piece Java code step-by-step. In doing so, you'll learn some of the amazing feats of optimization that JVMs can perform, but also some surprisingly simple things that prevent your code from running fast.
An overview of the inner-workings of OpenJDK - with emphasis on...
- what triggers the just-in-time compiler (JIT)
- types of speculative optimizations performed by the JIT
- aspects of the Java language & ecosystem that make ahead-of-time (AOT) compilation challenging
JDays 2016 - Beyond Lambdas - the AftermathDaniel Sawano
This presentation was given by Daniel Deogun and Daniel Sawano at the JDays conference, Gothenburg, 2016.
-----------------
As Java developers we are used to having rich ecosystems of libraries and tools that make our lives easier. As of the release of Java 8, we finally got our hands on building blocks like lambdas, optionals, and streams. All sorts of tools that help us write more concise code. But now, when the honeymoon is over, are there any downsides to Java 8 or is it a silver bullet? Are there any new anti-patterns emerging? Or subtle bugs caused by the new style of programming? Have there been any lessons learned? Are there any best practices? If you are interested in learning about the challenges encountered when moving over to a functional style of Java programming, what code constructs to avoid, and best practices to use, well then this session is for you.
Spotify 2016 - Beyond Lambdas - the AftermathDaniel Sawano
This presentation was given by Daniel Deogun and Daniel Sawano at the Spotify Java Conference, Stockholm, 2016.
-----------------
As Java developers we are used to having rich ecosystems of libraries and tools that make our lives easier. As of the release of Java 8, we finally got our hands on building blocks like lambdas, optionals, and streams. All sorts of tools that help us write more concise code. But now, when the honeymoon is over, are there any downsides to Java 8 or is it a silver bullet? Are there any new anti-patterns emerging? Or subtle bugs caused by the new style of programming? Have there been any lessons learned? Are there any best practices? If you are interested in learning about the challenges encountered when moving over to a functional style of Java programming, what code constructs to avoid, and best practices to use, well then this session is for you.
GeeCon 2016 - Beyond Lambdas, the AftermathDaniel Sawano
This presentation was given by Daniel Deogun and Daniel Sawano at the GeeCon Developer Conference, Kraków, 2016.
-----------------
As Java developers we are used to having rich ecosystems of libraries and tools that make our lives easier. As of the release of Java 8, we finally got our hands on building blocks like lambdas, optionals, and streams. All sorts of tools that help us write more concise code. But now, when the honeymoon is over, are there any downsides to Java 8 or is it a silver bullet? Are there any new anti-patterns emerging? Or subtle bugs caused by the new style of programming? Have there been any lessons learned? Are there any best practices? If you are interested in learning about the challenges encountered when moving over to a functional style of Java programming, what code constructs to avoid, and best practices to use, well then this session is for you.
Functional Patterns for the non-mathematicianBrian Lonsdorf
Fluentconf 2014 talk:
Functional design patterns such as lenses, arrows, functors, and monads all come from category theory. To fully grok them, you’ll probably have to wade through the whitest white papers, fighting the mathematical syntax and abstract examples.
I’m hoping to demonstrate the ideas into javascript. I’ll be showing direct and practical applications for every day programming.
An overview of the inner-workings of OpenJDK - with emphasis on...
- what triggers the just-in-time compiler (JIT)
- types of speculative optimizations performed by the JIT
- aspects of the Java language & ecosystem that make ahead-of-time (AOT) compilation challenging
JDays 2016 - Beyond Lambdas - the AftermathDaniel Sawano
This presentation was given by Daniel Deogun and Daniel Sawano at the JDays conference, Gothenburg, 2016.
-----------------
As Java developers we are used to having rich ecosystems of libraries and tools that make our lives easier. As of the release of Java 8, we finally got our hands on building blocks like lambdas, optionals, and streams. All sorts of tools that help us write more concise code. But now, when the honeymoon is over, are there any downsides to Java 8 or is it a silver bullet? Are there any new anti-patterns emerging? Or subtle bugs caused by the new style of programming? Have there been any lessons learned? Are there any best practices? If you are interested in learning about the challenges encountered when moving over to a functional style of Java programming, what code constructs to avoid, and best practices to use, well then this session is for you.
Spotify 2016 - Beyond Lambdas - the AftermathDaniel Sawano
This presentation was given by Daniel Deogun and Daniel Sawano at the Spotify Java Conference, Stockholm, 2016.
-----------------
As Java developers we are used to having rich ecosystems of libraries and tools that make our lives easier. As of the release of Java 8, we finally got our hands on building blocks like lambdas, optionals, and streams. All sorts of tools that help us write more concise code. But now, when the honeymoon is over, are there any downsides to Java 8 or is it a silver bullet? Are there any new anti-patterns emerging? Or subtle bugs caused by the new style of programming? Have there been any lessons learned? Are there any best practices? If you are interested in learning about the challenges encountered when moving over to a functional style of Java programming, what code constructs to avoid, and best practices to use, well then this session is for you.
GeeCon 2016 - Beyond Lambdas, the AftermathDaniel Sawano
This presentation was given by Daniel Deogun and Daniel Sawano at the GeeCon Developer Conference, Kraków, 2016.
-----------------
As Java developers we are used to having rich ecosystems of libraries and tools that make our lives easier. As of the release of Java 8, we finally got our hands on building blocks like lambdas, optionals, and streams. All sorts of tools that help us write more concise code. But now, when the honeymoon is over, are there any downsides to Java 8 or is it a silver bullet? Are there any new anti-patterns emerging? Or subtle bugs caused by the new style of programming? Have there been any lessons learned? Are there any best practices? If you are interested in learning about the challenges encountered when moving over to a functional style of Java programming, what code constructs to avoid, and best practices to use, well then this session is for you.
Functional Patterns for the non-mathematicianBrian Lonsdorf
Fluentconf 2014 talk:
Functional design patterns such as lenses, arrows, functors, and monads all come from category theory. To fully grok them, you’ll probably have to wade through the whitest white papers, fighting the mathematical syntax and abstract examples.
I’m hoping to demonstrate the ideas into javascript. I’ll be showing direct and practical applications for every day programming.
This presentation is on advanced debugging using Java bytecodes (presented in Core Java meetup on 1st October in Accion Labs). If you are a Java developer and are interested in knowing advanced debugging techniques or understanding bytecodes, this presentation is for you.
Q3 GIVEN THE TREND EQUATION NO OF STUDENTS-3000+200 YEAR BASE: 2003-0
1.INTERPRET EQUATION RESULTS 2.FORECAST FOR 2020 3.WHEN WILL THE NO OF
STUDENTS REACH 6000
Solution
x no of years from 2003 y no of students y = 3000+200x 1) The regression
equation has a positive slope of 200 y intercept is 3000 i.e. no of students in the year 2000
Thus for every year 200 students increase 2) For 2020, x = 17, y = 3000+200(17) = 6400
3) When y =6000, 6000 = 3000+200x or x = 15 Hence in year 2018 students reach 6000
B Regression C D. All the above.
The Roman Empire A Historical Colossus.pdfkaushalkr1407
The Roman Empire, a vast and enduring power, stands as one of history's most remarkable civilizations, leaving an indelible imprint on the world. It emerged from the Roman Republic, transitioning into an imperial powerhouse under the leadership of Augustus Caesar in 27 BCE. This transformation marked the beginning of an era defined by unprecedented territorial expansion, architectural marvels, and profound cultural influence.
The empire's roots lie in the city of Rome, founded, according to legend, by Romulus in 753 BCE. Over centuries, Rome evolved from a small settlement to a formidable republic, characterized by a complex political system with elected officials and checks on power. However, internal strife, class conflicts, and military ambitions paved the way for the end of the Republic. Julius Caesar’s dictatorship and subsequent assassination in 44 BCE created a power vacuum, leading to a civil war. Octavian, later Augustus, emerged victorious, heralding the Roman Empire’s birth.
Under Augustus, the empire experienced the Pax Romana, a 200-year period of relative peace and stability. Augustus reformed the military, established efficient administrative systems, and initiated grand construction projects. The empire's borders expanded, encompassing territories from Britain to Egypt and from Spain to the Euphrates. Roman legions, renowned for their discipline and engineering prowess, secured and maintained these vast territories, building roads, fortifications, and cities that facilitated control and integration.
The Roman Empire’s society was hierarchical, with a rigid class system. At the top were the patricians, wealthy elites who held significant political power. Below them were the plebeians, free citizens with limited political influence, and the vast numbers of slaves who formed the backbone of the economy. The family unit was central, governed by the paterfamilias, the male head who held absolute authority.
Culturally, the Romans were eclectic, absorbing and adapting elements from the civilizations they encountered, particularly the Greeks. Roman art, literature, and philosophy reflected this synthesis, creating a rich cultural tapestry. Latin, the Roman language, became the lingua franca of the Western world, influencing numerous modern languages.
Roman architecture and engineering achievements were monumental. They perfected the arch, vault, and dome, constructing enduring structures like the Colosseum, Pantheon, and aqueducts. These engineering marvels not only showcased Roman ingenuity but also served practical purposes, from public entertainment to water supply.
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxEduSkills OECD
Andreas Schleicher presents at the OECD webinar ‘Digital devices in schools: detrimental distraction or secret to success?’ on 27 May 2024. The presentation was based on findings from PISA 2022 results and the webinar helped launch the PISA in Focus ‘Managing screen time: How to protect and equip students against distraction’ https://www.oecd-ilibrary.org/education/managing-screen-time_7c225af4-en and the OECD Education Policy Perspective ‘Students, digital devices and success’ can be found here - https://oe.cd/il/5yV
Read| The latest issue of The Challenger is here! We are thrilled to announce that our school paper has qualified for the NATIONAL SCHOOLS PRESS CONFERENCE (NSPC) 2024. Thank you for your unwavering support and trust. Dive into the stories that made us stand out!
Unit 8 - Information and Communication Technology (Paper I).pdfThiyagu K
This slides describes the basic concepts of ICT, basics of Email, Emerging Technology and Digital Initiatives in Education. This presentations aligns with the UGC Paper I syllabus.
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdfTechSoup
In this webinar you will learn how your organization can access TechSoup's wide variety of product discount and donation programs. From hardware to software, we'll give you a tour of the tools available to help your nonprofit with productivity, collaboration, financial management, donor tracking, security, and more.
The Art Pastor's Guide to Sabbath | Steve ThomasonSteve Thomason
What is the purpose of the Sabbath Law in the Torah. It is interesting to compare how the context of the law shifts from Exodus to Deuteronomy. Who gets to rest, and why?
Synthetic Fiber Construction in lab .pptxPavel ( NSTU)
Synthetic fiber production is a fascinating and complex field that blends chemistry, engineering, and environmental science. By understanding these aspects, students can gain a comprehensive view of synthetic fiber production, its impact on society and the environment, and the potential for future innovations. Synthetic fibers play a crucial role in modern society, impacting various aspects of daily life, industry, and the environment. ynthetic fibers are integral to modern life, offering a range of benefits from cost-effectiveness and versatility to innovative applications and performance characteristics. While they pose environmental challenges, ongoing research and development aim to create more sustainable and eco-friendly alternatives. Understanding the importance of synthetic fibers helps in appreciating their role in the economy, industry, and daily life, while also emphasizing the need for sustainable practices and innovation.
The Indian economy is classified into different sectors to simplify the analysis and understanding of economic activities. For Class 10, it's essential to grasp the sectors of the Indian economy, understand their characteristics, and recognize their importance. This guide will provide detailed notes on the Sectors of the Indian Economy Class 10, using specific long-tail keywords to enhance comprehension.
For more information, visit-www.vavaclasses.com
Palestine last event orientationfvgnh .pptxRaedMohamed3
An EFL lesson about the current events in Palestine. It is intended to be for intermediate students who wish to increase their listening skills through a short lesson in power point.
1. www.javaassignmenthelp.net
Most Popular Java Problems and Solutions
If looking for Java problems and their solutions, check out this page and you will learn of the
most popular ones that you might want to learn about so that you can start memorizing and
applying them when needed.
List of Java Problems and Solutions
1. Create a Java program displaying Hello World on screen
Solution:
public class HelloWorld
{
public static void main(String[] args)
{
System.out.println("Hello World.");
}
}
2. www.javaassignmenthelp.net
2. Create a Java program displaying asterisk pattern.
Solution:
*****
*****
*****
*****
*****
public class JavaExercises
{
public static void main(String[] args)
{
printAsterisk();
}
static void printAsterisk(){
System.out.println("*****");
System.out.println("*****");
System.out.println("*****");
System.out.println("*****");
System.out.println("*****");
}
}
3. Create a Java program declaring 2 integer variables, 1 float variable as
well as 1 string variable, then assign 10, 12.5 as well as “Java
programming” respectively. After that, display the values on screen.
Solution:
public class JavaExercises
{
3. www.javaassignmenthelp.net
public static void main(String[] args)
{
accessVariables();
}
static void accessVariables(){
int x;
float y;
String s;
x = 10;
y = 12.5f;
s = "Java programming";
System.out.println(x);
System.out.println(y);
System.out.println(s);
}
}
4. Create a Java program with the use of the BufferedReader class in
prompting user to input her or his name. The output will be like this:
Hello Dara!
Solution:
import java.io.*;
public class JavaExercises
{
public static void main(String[] args)
{
printName();
}
static void printName(){
String pname=null;
try{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter your name:");
pname=br.readLine();
}catch(IOException e){}
5. www.javaassignmenthelp.net
5
7
9
11
13
15
17
19
7. Write an example method printing square numbers up to one hundred.
Solution:
squares()
*** Output ***
1
4
9
16
25
36
49
64
81
100
8. Write an example loop in printing out 4 random integers between one
and ten.
6. www.javaassignmenthelp.net
Solution:
random4()
*** Output ***
3
5
2
8
9. Write an example method printing out positive even numbers that is less
than n.
Solution:
1: even(20)
2: *** Output ***
3: 2
4: 4
5: 6
6: 8
7: 10
8: 12
9: 14
10: 16
11: 18
10.Write an example method printing out powers of two from 21
up to 2n.
Solution:
powers(8)
7. www.javaassignmenthelp.net
: *** Output ***
2
4
8
16
32
64
128
256
11. Create an example program that outputs “ Are we there yet?” Wait for
the input and if it say “yes”, then the outputs program is “good” and
then exit.
Solution:
"Are we there yet?"
No
"Are we there yet?"
Spoons
"Are we there yet?"
Yes
Good!
12. Create an example method using nested loops in producing a pattern.
Solution:
triangle()
*** Output ***
8. www.javaassignmenthelp.net
*
**
***
****
*****
13. Create an example method printing out 4x4 table square.
Solution:
tableSquare()
*** Output ***
A 4 x 4 table square
| 1 | 2 | 3 | 4 |
| 1 | 2 | 3 | 4 |
| 2 | 4 | 6 | 8 |
| 3 | 6 | 9 | 12 |
| 4 | 8 | 12 | 16 |
14. Write an example extending your answer to last question producing
method printing out n x n table square.
Solution:
tableSquares(6)
*** Output ***
A 6 x 6 table square
| 1 | 2 | 3 | 4 | 5 | 6 |
| 2 | 4 | 6 | 8 | 10 | 12 |
| 3 | 6 | 9 | 12 | 15 | 18 |
9. www.javaassignmenthelp.net
| 4 | 8 | 12 | 16 | 20 | 24 |
| 5 | 10 | 15 | 20 | 25 | 30 |
| 6 | 12 | 18 | 24 | 30 | 36 |
15. Write an example method printing out string array, 1 element for every
line
Solution:
String [] breakfast = {"Sausage", "Eggs", "Beans", "Bacon", "Tomatoes", "Mushrooms"};
printArray(breakfast)
*** Output ***
Sausage
Eggs
Beans
Bacon
Tomatoes
Mushrooms
16. Create an example method returning to the last element of the string
array.
Solution:
String [] breakfast = {"Sausage", "Eggs", "Beans", "Bacon", "Tomatoes", "Mushrooms"}
System.out.println(lastElement(breakfast));
*** Output ***
Mushrooms
10. www.javaassignmenthelp.net
17. Create an example method returning to the last, but 1 element of the
string array.
Solution:
String [] breakfast = {"Sausage", "Eggs", "Beans", "Bacon", "Tomatoes", "Mushrooms"}
System.out.println(lastButOne(breakfast));
*** Output ***
Tomatoes
18. Create an example method reversing elements of the Array.
Solution:
String [] breakfast = {"Sausage", "Eggs", "Beans", "Bacon", "Tomatoes", "Mushrooms"};
System.out.println(reverse(breakfast));
*** Output ***
: Mushrooms
: Tomatoes
: Bacon
: Beans
: Eggs
: Sausage
: Tails
19. Write a method testing to see if the array is palindromic. For example,
elements are same when it is reversed.
Solution:
11. www.javaassignmenthelp.net
String [] palindromic = {"Sausage", "Eggs", "Beans", "Beans", "Eggs", "Sausage"};
String [] breakfast = {"Sausage", "Eggs", "Beans", "Bacon", "Tomatoes", "Mushrooms"}
System.out.println(isPalindrome(palindromic));
System.out.println(isPalindrome(breakfast));
*** Output ***
True
False
20. Write a method printing out int array with the consecutive duplicated
eliminated.
Solution:
int [] nums = {1,1,3,3,3,2,2,2,1,1,1,1,4,4,4,4};
compress(nums)
*** Output ***
5: 1
: 3
: 2
: 1
: 4
: 1
: 1
21. Pack consecutive duplicated of the char array into the strings.
Solution:
12. www.javaassignmenthelp.net
char [] letters = {'a' 'a' 'a' 'a' 'b' 'c' 'c' 'a' 'a' 'd' 'e' 'e' 'e' 'e'};
pack(nums)
*** Output ***
: aaaa, b, cc, aa, d, eeee
22. Create a method returning the number of words in the string.
Solution:
String s = "I never saw a purple cow"
System.out.println(countWords(s));
*** Output ***
6
23. Create a method counting instances of letter “e” in the string.
Solution:
String s = "I never saw a purple cow"
System.out.println(countEs(s));
*** Output ***
3
24. Write a method returning number of the alphanumeric characters in
string.
Solution:
String s = "1984 by George Orwell."
13. www.javaassignmenthelp.net
System.out.println(countChars(s));
*** Output ***
18
25. Create a method returning the string, reversed.
Solution:
String s = "I never saw a purple cow"
System.out.println(reverse(s));
*** Output ***
woc elprup a was reven I
26. Create a method testing if the string is palindrome.
Solution:
String sentence = "I never saw a purple cow"
String palindrome = "rotavator"
System.out.println(isPalindrome(sentence));
System.out.println(isPalindrome(palindrome));
*** Output ***
False
True
27.Create improved palindrome that disregard punctuation, case and
spaces as well as recognize sentences like “ A man, a plan, a canal,
Panama!” as palindrome.
14. www.javaassignmenthelp.net
Solution:
String s = "I never saw a purple cow"
String p = "Rise to vote, Sir!"
System.out.println(isPalindrome(s));
System.out.println(isPalindrome(p));
*** Output ***
False
True
28. Write a method replacing vowels in the word with the asterisks.
Solution:
String s = "I never saw a purple cow"
star(s)
*** Output ***
* n*v*r s*w * p*rpl* c*w
29. Create method spelling out words. For example, This will become T-H-I-
S.
Solution:
String s = "I never saw a purple cow"
spellOut(s)
*** Output ***
I N-E-V-E-R S-A-W A P-U-R-P-L-E C-O-W
15. www.javaassignmenthelp.net
30.In simple substitution cipher, A=1, B=2, C=3 and others. Create a
method encoding sentence with the use of cipher.
Solution:
String s = "Hello World"
encode(s)
*** Output ***
8,5,12,12,15 23,15,18,12,4
31. Create decoder method for the substitution cipher.
Solution:
String s = "9 14,5,22,5,18 19,1,23 1 16,21,18,16,12,5 3,15,23"
decode(s)
*** Output ***
i never saw a purple cow
32. Determine if the given integer number is a prime.
Solution:
public class NNArithmetic {
NNArithmetic()
{
System.out.println(isPrime(7));
16. www.javaassignmenthelp.net
}
boolean isPrime(int a)
{
//Special cases
if(a==1) return false;
if(a==2) return true;
boolean prime = true;
int count = 2;
do
{
if (a%count==0)
{
prime = false;
}
count++;
} while(prime == true && count*count <=a);
return prime;
}
public static void main(String[] args)
17. www.javaassignmenthelp.net
{
new NNArithmetic();
}
}
33. Use the Euclid’s Algorithm in determining Greatest Common Divisor of
2 positive integer numbers.
Solution:
public class NNArithmetic {
NNArithmetic()
{
System.out.println(gcd (1071, 462));
System.out.println(gcd (6, 35));
System.out.println(gcd (36, 63));
}
int gcd(int a, int b)
{
if(b>a) //Make sure the first number is largest
{
int temp = a;
a = b;
18. www.javaassignmenthelp.net
b = temp;
}
while(b>0)
{
int remainder = a%b;
a = b;
b = remainder;
}
return a;
}
public static void main(String[] args)
{
new NNArithmetic();
}
}
34. Determine whether 2 positive integer numbers are co-prime. 2 numbers
are co-prime if the greatest common divisor equals to 1.
Solution:
public class NNArithmetic {
NNArithmetic()
20. www.javaassignmenthelp.net
boolean isCoprime(int a, int b)
{
return (gcd(a,b) ==1) ? true : false;
}
public static void main(String[] args)
{
new NNArithmetic();
}
}
35. Calculate Euler’s totient function phi(m). For instance, m = 10: r =
1,3,7,9; thus phi(m) = 4. Note the special case: phi(1) = 1.
Solution:
public class NNArithmetic {
NNArithmetic()
{
System.out.println(phi(10));
}
int gcd(int a, int b)
{
if(b>a) //Make sure the first number is largest
{
21. www.javaassignmenthelp.net
int temp = a;
a = b;
b = temp;
}
while(b>0)
{
int remainder = a%b;
a = b;
b = remainder;
}
return a;
}
boolean isCoprime(int a, int b)
{
return (gcd(a,b) ==1) ? true : false;
}
int phi(int m)
{
if (m==1) return 1; //Special Case
22. www.javaassignmenthelp.net
int phi = 0;
for(int i = 1; i<m; i++)
{
if (isCoprime(m,i)) phi++;
}
return phi;
}
public static void main(String[] args)
{
new NNArithmetic();
}
}
36. Create a method printing prime factors of given positive integer.
Solution:
public class NNArithmetic {
NNArithmetic()
{
printPrimeFactors(315);
printPrimeFactors(98);
}
void printPrimeFactors(int n)
23. www.javaassignmenthelp.net
{
for(int i = 2; i*i<=n; i++)
{
while(n%i == 0)
{
System.out.print(i + " ");
n = n/i;
}
}
if(n>1) System.out.print(n + "n");
else System.out.println("");
}
public static void main(String[] args)
{
new NNArithmetic();
}
}
37. With the given integers range by its lower limit and upper limit,
construct a list of the prime numbers within that range.
Solution:
public class NNArithmetic {
NNArithmetic()
25. www.javaassignmenthelp.net
void printPrimesInRange(int a , int b)
{
for (int i = a; i<=b; i++)
{
if (isPrime(i)) System.out.print(i + " ");
}
System.out.println("");
}
public static void main(String[] args)
{
new NNArithmetic();
}
}
38. Create predicate in finding 2 prime numbers summing up to given even
number.
Solution:
public class NNArithmetic {
NNArithmetic()
{
printGoldbachPair(28);
printGoldbachPair(1856);
}
26. www.javaassignmenthelp.net
boolean isPrime(int a)
{
//Special cases
if(a==1) return false;
if(a==2) return true;
boolean prime = true;
int count = 2;
do
{
if (a%count==0)
{
prime = false;
}
count++;
} while(prime == true && count*count <=a);
return prime;
}
int [] goldbachPair(int n)
{
int count = 2;
int [] pair = new int[2];
28. www.javaassignmenthelp.net
}
}
39. With the given integers by lower limit and upper limit, print list of even
numbers as well as their Goldbach composition. Find out how many
cases there are in range of 2..3000.
Solution:
public class NNArithmetic {
NNArithmetic()
{
printGoldbachList(9, 20);
printGoldbachList(1,2000,50);
}
boolean isPrime(int a)
{
//Special cases
if(a==1) return false;
if(a==2) return true;
boolean prime = true;
int count = 2;
do
30. www.javaassignmenthelp.net
}
return pair;
}
void printGoldbachPair(int n)
{
int [] pair = goldbachPair(n);
System.out.println(pair[0] + " + " + pair [1] + " = " + n);
}
void printGoldbachList(int a, int b)
{
if(a%2==1) a++; // make sure start on even number
for (int i = a ; i<=b ; i+=2)
{
printGoldbachPair(i);
}
}
void printGoldbachList(int a, int b, int min)
{
if(a%2==1) a++; // make sure start on even number
for (int i = a ; i<=b ; i+=2)
31. www.javaassignmenthelp.net
{
int [] pair = goldbachPair(i);
if(pair[0] > min && pair[1] > min) printGoldbachPair(i);
}
}
public static void main(String[] args)
{
new NNArithmetic();
}
}
40. Create a method printing out the string array, 1 element for every line.
Solution:
public class NNArrays {
NNArrays()
{
String [] breakfast = {"Sausage", "Eggs", "Beans", "Bacon", "Tomatoes", "Mushrooms"};
printArray(breakfast);
//Alternative Method
printArrayAlt(breakfast);
}
32. www.javaassignmenthelp.net
void printArray(String [] array)
{
for(int i = 0; i<array.length; i++)
{
System.out.println(array[i]);
}
}
//Alternative method using for each loop
void printArrayAlt(String [] array)
{
for(String s: array)
{
System.out.println(s);
}
}
public static void main(String[] args)
{
new NNArrays();
}
}
41. Write a method returning last element of the string array.
33. www.javaassignmenthelp.net
Solution:
public class NNArrays {
NNArrays()
{
String [] breakfast = {"Sausage", "Eggs", "Beans", "Bacon", "Tomatoes", "Mushrooms"};
System.out.println(lastElement(breakfast));
}
String lastElement(String [] array)
{
return array[array.length-1];
}
public static void main(String[] args)
{
new NNArrays();
}
}
42. Create a method returning last, but 1 element of the string array.
Solution:
public class NNArrays {
34. www.javaassignmenthelp.net
NNArrays()
{
String [] breakfast = {"Sausage", "Eggs", "Beans", "Bacon", "Tomatoes", "Mushrooms"};
//Added two extra arrays for testing
String [] coin = {"Heads", "Tails"};
String [] lonely = {"solo"};
System.out.println(lastButOne(breakfast));
System.out.println(lastButOneSafer(breakfast));
System.out.println(lastButOneSafer(coin));
System.out.println(lastButOneSafer(lonely));
}
String lastButOne(String [] array)
{
return array[array.length-2];
}
// The previous method will throw an
// arrayIndexOutOfBoundsException for arrays of length <2.
// This method will return an empty string if length <2
String lastButOneSafer(String [] array)
{
35. www.javaassignmenthelp.net
if (array.length<2)
{
return "";
}
else
{
return array[array.length-2];
}
}
public static void main(String[] args)
{
new NNArrays();
}
}
43. Create a method returning elements of the Array in a reverse order.
Solution:
public class NNArrays {
NNArrays()
{
String [] breakfast = {"Sausage", "Eggs", "Beans", "Bacon", "Tomatoes", "Mushrooms"};
//Added two extra arrays for testing
String [] coin = {"Heads", "Tails"};
37. www.javaassignmenthelp.net
return array;
}
public static void main(String[] args)
{
new NNArrays();
}
}
44. Create a method testing to see if the array is a palindromic. For
instance, elements are same when it is being reversed.
Solution:
public class NNArrays {
NNArrays()
{
String [] breakfast = {"Sausage", "Eggs", "Beans", "Bacon", "Tomatoes", "Mushrooms"};
String [] lonely = {"solo"};
String [] palindromic = {"Sausage", "Eggs", "Beans",
"Beans", "Eggs", "Sausage"};
System.out.println(isPalindrome(palindromic));
System.out.println(isPalindrome(breakfast));
System.out.println(isPalindrome(lonely));
}
38. www.javaassignmenthelp.net
boolean isPalindrome(String [] array)
{
boolean isPal = true;
for (int i = 0; i<array.length/2; i++)
{
if (!array[i].equals(array[array.length -i -1]))
isPal = false;
}
return isPal;
}
// The following method doesn't work.
// Need to compare individual elements
boolean isPalindromeWrong(String [] array)
{
if (array.equals(reverse(array)))
{
return true;
}
else
{
39. www.javaassignmenthelp.net
return false;
}
}
String [] reverse(String [] array)
{
for(int i = 0; i<array.length/2;i++)
{
String temp = array[i];
array[i] = array[array.length-i-1];
array[array.length-i-1] = temp;
}
return array;
}
public static void main(String[] args)
{
new NNArrays();
}
}
45. Create a method printing out int array with the consecutives duplicates
eliminated.
Solution:
40. www.javaassignmenthelp.net
public class NNArrays {
NNArrays()
{
int [] nums = {1,1,3,3,3,2,2,2,1,1,1,1,4,4,4,4};
int [] num2 = {1,1};
int [] num1 = {1};
compress(nums);
compress(num2);
compress(num1);
}
void compress(int [] array)
{
System.out.println(array[0]);
for (int i = 1; i<array.length; i++)
{
if (array[i]!=array[i-1])
{
System.out.println(array[i]);
}
}
41. www.javaassignmenthelp.net
}
public static void main(String[] args)
{
new NNArrays();
}
}
46. Create a method printing 2D array of any sizes, then test it with the use
of 3 x 3 tic-tact-toe grid.
Solution:
public class NNStringArray {
NNStringArray()
{
tictactoe();
}
void tictactoe()
{
String [][] grid = new String[3][3];
for(int i = 0; i<grid.length; i++)
{
43. www.javaassignmenthelp.net
}
}
47. Create a 8 x 8 array representing chess board. You should print out
array with the alternate “X” and “O”.
Solution:
public class NNStringArray {
NNStringArray()
{
chess();
}
void printArray(String [][] grid)
{
for(int i = 0; i<grid.length; i++)
{
for(int j = 0; j<grid.length; j++)
{
System.out.print(" | " + grid[i][j]);
}
System.out.println(" | ");
}
}
44. www.javaassignmenthelp.net
void chess()
{
String [][] grid = new String[8][8];
boolean fill = true;
for(int i = 0; i<grid.length; i++)
{
for (int j = 0; j<grid.length; j++)
{
grid[i][j] = fill ? "X" : "O";
fill = !fill;
}
fill = !fill;
}
printArray(grid);
}
public static void main(String[] args) {
// TODO code application logic here
new NNStringArray();
}
}
48. Create a method converting digits to words.
Solution:
45. www.javaassignmenthelp.net
public class NNStringArray {
NNStringArray()
{
System.out.println(digitsToWords("35001922"));
}
String digitsToWords(String s)
{
String words = "";
String [] digits =
{"Oh","One","Two","Three","Four","Five","Six","Seven","Eight","Nine"};
for (int i = 0; i<s.length();i++)
{
int number = Integer.parseInt(s.substring(i,i+1));
words = words + digits[number] + " ";
}
return words;
}
public static void main(String[] args) {
// TODO code application logic here
new NNStringArray();
46. www.javaassignmenthelp.net
}
}
49. Create a method converting time into words.
Solution:
public class NNStringArray {
NNStringArray()
{
System.out.println(timeToWords("2:05"));
System.out.println(timeToWords("2:47"));
System.out.println(timeToWords("12:00"));
System.out.println(timeToWords("2:00"));
System.out.println(timeToWords("12:30"));
System.out.println(timeToWords("4:29"));
System.out.println(timeToWords("7:25"));
System.out.println(timeToWords("12:45"));
System.out.println(timeToWords("12:55"));
}
String timeToWords(String s)
{
String time = "";
String [] input = s.split(":");
47. www.javaassignmenthelp.net
String [] times = {"o'clock","one","two","three","four", "five", "six",
"seven","eight","nine","ten","eleven","twelve","thirteen","fourteen",
"quarter","sixteen","seventeen","eighteen","nineteen","twenty",
"twenty one","twenty two","twenty three","twenty four",
"twenty five","twenty six","twenty seven","twenty eight",
"twenty nine","half past"};
int hours = Integer.parseInt(input[0]);
int minutes = Integer.parseInt(input[1]);
//Watch out for e.g. 12:50 = Ten to One
String sayMinutesp = minutes%5 != 0 ? " minutes" : "";
if (hours == 12 && minutes > 30) hours = 1;
if (minutes == 0)
{
time = times[hours] + " o'clock";
}
else if (minutes == 15)
{
time = "Quarter past " + times[hours];
}
else if (minutes == 45)
{
48. www.javaassignmenthelp.net
time = "Quarter to " + times[hours];
}
else if (minutes>30)
{
time = times[60-minutes]+ sayMinutesp + " to " + times[hours];
}
else
{
time = times[minutes] + sayMinutesp + " past " + times[hours];
}
return time;
}
public static void main(String[] args) {
// TODO code application logic here
new NNStringArray();
}
}
50. Create a program with the use of arrays translating plain text to morse
code.
Solution:
A B C D E F G
49. www.javaassignmenthelp.net
.- -… -.-. -.. . ..-. –.
H I J K L M
…. .. .— -.- .-.. —
N O P Q R S T
-. — .–. –.- .-. … –
U V W X Y Z
..- …- .– -..- -.– __..
public class NNStringArray {
NNStringArray()
{
System.out.println(morse("I never saw a purple cow"));
}
String morse(String s)
{
s = s.toLowerCase();
String cipherText = "";
String code [] = {".-","-...","-.-.","-..",".","..-.","--.", "....",
"..", ".---","-.-",".-..","--","-.","---",".--.","--.-",".-.",
"...","-","..-","...-",".--","-..-","-.--","--..", "/"};
50. www.javaassignmenthelp.net
for (int i = 0; i<s.length(); i++)
{
int number = s.charAt(i) == ' ' ? 26 : s.charAt(i)-97;
cipherText = cipherText + code[number] + " ";
}
return cipherText;
}
public static void main(String[] args) {
// TODO code application logic here
new NNStringArray();
}
}
51. Create a program with the use of arrays translating morse back into
plain text.
Solution:
public class NNStringArray {
NNStringArray()
{
System.out.println(demorse(".. / -. . ...- . .-. / ... .- .-- / .- / .--. ..- .-. .--. .-.. . / -.-. --- .--"));
}
String demorse(String s)
52. www.javaassignmenthelp.net
{
char c = (char)(j+97);
plainText = plainText + Character.toString(c);
}
}
}
}
return plainText;
}
public static void main(String[] args) {
// TODO code application logic here
new NNStringArray();
}
}
52. Rewrite morse code program with the use of Hashmap.
Solution:
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
public class NNStringArray {
57. www.javaassignmenthelp.net
}
String demorseHash(String s)
{
String [] letters = s.split("s+");
String plaintext = "";
for (int i = 0; i<letters.length; i++)
{
for (Entry<String, String> entry : morse.entrySet()) {
if (entry.getValue().equals(letters[i])) {
plaintext = plaintext + entry.getKey();
}
}
}
return plaintext;
}
public static void main(String[] args) {
// TODO code application logic here
new NNStringArray();
}
58. www.javaassignmenthelp.net
}
54. To write a java program to print fibonacci series upto 100, you need a
code. Give a code of it.
Solution:
import java.util.Scanner;
/**
* Java program to calculate and print Fibonacci number using both recursion
* and Iteration.
* Fibonacci number is sum of previous two Fibonacci numbers fn= fn-1+ fn-2
* first 10 Fibonacci numbers are 1, 1, 2, 3, 5, 8, 13, 21, 34, 55
*
* @author Javin
*/
publicclass FibonacciCalculator {
publicstaticvoid main(String args[]) {
//input to print Fibonacci series upto how many numbers
System.out.println("Enter number upto which Fibonacci series to print: ");
int number = new Scanner(System.in).nextInt();
System.out.println("Fibonacci series upto " + number +" numbers : ");
//printing Fibonacci series upto number
59. www.javaassignmenthelp.net
for(int i=1; i<=number; i++){
System.out.print(fibonacci2(i) +" ");
}
}
/*
* Java program for Fibonacci number using recursion.
* This program uses tail recursion to calculate Fibonacci number for a given number
* @return Fibonacci number
*/
publicstaticint fibonacci(int number){
if(number == 1 || number == 2){
return 1;
}
return fibonacci(number-1) + fibonacci(number -2); //tail recursion
}
/*
* Java program to calculate Fibonacci number using loop or Iteration.
* @return Fibonacci number
*/
public static int fibonacci2(int number){
if(number == 1 || number == 2){
return 1;
60. www.javaassignmenthelp.net
}
int fibo1=1, fibo2=1, fibonacci=1;
for(int i= 3; i<= number; i++){
//Fibonacci number is sum of previous two Fibonacci number
fibonacci = fibo1 + fibo2;
fibo1 = fibo2;
fibo2 = fibonacci;
}
return fibonacci; //Fibonacci number
}
}
Output:
Enter number upto which Fibonacci series to print:
12
Fibonacci series upto 12 numbers :
1 1 2 3 5 8 13 21 34 55 89 144
55. In java program to print fibonacci series upto 100, show how to create
Fibonacci series.
Solution:
Code:
?
package com.java2novice.algos;
61. www.javaassignmenthelp.net
public class MyFibonacci {
public static void main(String a[]){
int febCount = 15;
int[] feb = new int[febCount];
feb[0] = 0;
feb[1] = 1;
for(int i=2; i < febCount; i++){
feb[i] = feb[i-1] + feb[i-2];
}
for(int i=0; i< febCount; i++){
System.out.print(feb[i] + " ");
}
56. Show how to create Fibonacci series Java.
Solution:
public class JavaFibonacciSeriesExample {
public static void main(String[] args) {
62. www.javaassignmenthelp.net
//number of elements to generate in a series
int limit = 20;
long[] series = new long[limit];
//create first 2 series elements
series[0] = 0;
series[1] = 1;
//create the Fibonacci series and store it in an array
for(int i=2; i < limit; i++){
series[i] = series[i-1] + series[i-2];
}
//print the Fibonacci series numbers
System.out.println("Fibonacci Series upto " + limit);
for(int i=0; i< limit; i++){
System.out.print(series[i] + " ");
}
}
}
/*
63. www.javaassignmenthelp.net
Output of the Fibonacci Series Java Example would be
Fibonacci Series upto 20
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181
*/
57. Show how to print Fibonacci series between one to one hundred.
Solution:
Print fibonacci series between 1 to 100
like 0 1 1 2 3 5 8 13 21 34 55 89 144
?
publicclassFibonaci {
publicstaticvoidmain(String[] args) {
intn1 = 0, n2 = 1, num;
System.out.print(n1 + " "+
n2 + " ");
for(inti = 0; i < 100; i++) {
num = n2 + n1;
System.out.print(num + " ");
n1 = n2;
n2 = num;
}
}
}
64. www.javaassignmenthelp.net
58.In vending machine java program,for example; if you enter 5 for item
and.10 for paid, then why does it say Please insert another $1.4 instead
of 1.40? Even though 1.50 - 1.4 and 1.50 - 1.40 would be the same, how
can you solve the issue?
Solution: use arrays to help solve the issue.
59. Write a program finding Fibonacci series of given number. For
example:
Input – 8
Output - 1 1 2 3 5 8 13 21
Solution:
class Fibonacci{
publicstaticvoid main(String args[]){
int num = Integer.parseInt(args[0]); //taking no. as command line
argument.
System.out.println("*****Fibonacci Series*****");
int f1, f2=0, f3=1;
for(int i=1;i<=num;i++){
System.out.print(" "+f3+" ");
f1 = f2;
f2 = f3;
f3 = f1 + f2;
}
}
}
There you have our list of the most popular Java problems and solutions to learn
about, so refer to this guide when looking for formulas to use in specific Java
problems and contact us when you need Java assignment help!