[Solved] how to convert Date in to Feb 26, 2016 in java [duplicate]

import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static void main(String[] args) throws ParseException { String theInDate = “2/20/2016”; String theInFormat = “MM/dd/yyyy”; String theOutFormat = “MMM dd, yyyy”; final SimpleDateFormat theSdfInputFormatter = new SimpleDateFormat(theInFormat); final SimpleDateFormat theSdfOutputFormatter = new SimpleDateFormat(theOutFormat); final Date theDate = theSdfInputFormatter.parse(theInDate); final String theDateText = theSdfOutputFormatter.format(theDate); System.out.println(theDateText); … Read more

[Solved] Hello There! I am learning Java and completely unaware about it! what is diffrence between instance methods and non-static methods? [closed]

Instance method and non-static methods are same thing. Different types of methods are : Instance methods: Which are associated with objects. Class methods: These are the static methods. class Demo{ void hello(){ System.out.println(“Hello”); } static void hi(){ System.out.println(“hi”); } } To call instance method you need to do, new Demo().hello(); To call class method you … Read more

[Solved] Bizarre C++ code, trying to decipher

You didn’t specify the types, so I’m going to assume that these are all builtin C++ types, specifically arithmetic types (either integer type or a floating point type). If it is a user defined type, I can’t guarantee that anything I say below still applies. T& lhs.operator=(T& rhs) is the copy assignment operator (it could … Read more

[Solved] Java: How to print odd and even numbers from 2 separate threads using Executor framework

Its a modified version of jasons: import java.util.concurrent.Executor; import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicInteger; public class Test { public static void main(String[] args){ final int max = 100; final AtomicInteger i = new AtomicInteger(0); Executor dd = Executors.newFixedThreadPool(2); final Object lock = new Object(); dd.execute(new Runnable() { @Override public void run() { while (i.get() < max) { … Read more

[Solved] Find out the distance between two specific words in a String [closed]

Just a pointer, you can optimize the code: public static void main(String[] args) { String str = “The picture quality is great of this camera”; StringTokenizer st = new StringTokenizer(str); int numberOfWords = 0; boolean start = false; while(st.hasMoreTokens()){ String token = st.nextToken(); if(token.equals(“quality”)){ start = true; continue; } if(start) { if(token.equals(“great”)){ start = false; … Read more

[Solved] How to get the smallest list?

I dont know how you named your Lists, so I’m just going to call them List a, b, c and d. public List<?> getLongestList(List<?> a, List<?> b, List<?> c, List<?> d) { if (a.size() >= b.size() && a.size() >= c.size() && a.size() >= d.size()) return a; if (b.size() >= a.size() && b.size() >= c.size() && … Read more

[Solved] why am I getting this erroneous output?

If i understand the problem correctly it should take first int then scan the n lines and creating sort of 2 dimension list/array or so then should accept int of questions about what is in position (x,y) in this 2 dimensional object covering what is out of bounds as an “ERROR!”. import java.util.ArrayList; import java.util.Scanner; … Read more

[Solved] Ttrying to loop until user types in “Stop”

Your scope is screwed up all over the place, need to make sure the complete if/else is enclosed with {}, as it is most of your else’s don’t have anything to connect to. while (!sentenceInput.equals (“STOP”)) { if (sentencePunct == ‘?’) { if (remainder == 0) { System.out.println(“Yes”);` System.out.println(“Please Input another sentence (terminate with \”STOP … Read more

[Solved] Java: How to print odd and even numbers from 2 separate threads using Executor framework

Introduction The Executor framework in Java is a powerful tool for managing multiple threads. It allows you to easily create and manage threads, and to execute tasks in parallel. In this tutorial, we will learn how to use the Executor framework to print odd and even numbers from two separate threads. We will also discuss … Read more