[Solved] How do I return/implement the toString for the ArrayList? Also, just want to check that I’ve correctly created my objects?

You have a lot of error in your code : First Don’t ever name your variables with Upper letter in beginning, java use camelCase Second Don’t declare your variable with private public in your method. private ArrayList<Object> List = new ArrayList<Object>(); Third You can’t declare a method inside another method you have to close the … Read more

[Solved] When string.lenght() is 0 throw an exception

Try this out. This should give you Exception. public static void main(String[] args) throws Exception { Scanner keyboard = new Scanner(System.in); System.out.print(“Enter: “); String entry = keyboard.nextLine(); keyboard.close(); if (entry.length() == 0) { throw new Exception(“Exception Found”); } else { String reverse = reverse(entry); if (reverse.length() == 0) { throw new Exception(“Exception Found”); } else … Read more

[Solved] java how to convert for loop to do while loop

int sum = 0; int num; int i = 0; System.out.print(“Enter number: “); num = sc.nextInt(); do{ sum += i; i++; } while ( i <=num ); System.out.println(“The sum is ” + sum); Initialize i to zero, since do-while does first before checking, as opposed to for that checks first before doing. And your do-while … Read more

[Solved] Data type conversion [closed]

What do You mean? You have to cast f to long and b to char and also initialize them. l = (long) f; ch = (char) b; //—- float f = 3.14f; long l ; char ch; byte b = 38; l= (long) f; ch= (char) b; Check examples: int first = 3: int second … Read more

[Solved] Parallel streams in Java [closed]

From OCP : Oracle Certified Professional Java SE 8 Programmer || Study Guide : Exam 1z0-809 […] Depending on the number of CPUs available in your environment the following is a possible output of the code using a parallel stream […] Even better, the results scale with the number of processors. Scaling is the property … Read more

[Solved] Is it possible to do this in Java? [closed]

Here is the closest code: public class Stackoverflow_03262019 { public static void main(String[] args) { int[] arr=new int[5]; Arrays.fill(arr,0); Arrays.stream(arr).forEach(val-> System.out.println(val)); } } “` You can add any value instead of 0; 2 solved Is it possible to do this in Java? [closed]

[Solved] Why does Float has a constructor that allows double as an argument while Double doesn’t have a constructor with float as an argument in JAVA?

I think you’ve said why in your question, but just for clarity: Double(double) works just fine if you pass it a float, so there’s no need for Double(float). This is because in a constructor invocation (JLS§5.3), a widening primitive conversion (JLS§5.1.2) is allowed. float to double is a widening primitive conversion. But Float(float) would not … Read more

[Solved] Java language – show number 1-100

Your logic to print is fine, all you need to do is to wrap the code into a for loop and excute it from 1 to 100, e.g.: for(int zmienna = 0 ; zmienna <= 100 ; zmienna++){ if (zmienna % 5 == 0 && zmienna % 3 == 0) System.out.println(“FizzBizz”); else if (zmienna % … Read more

[Solved] E/AndroidRuntime: FATAL EXCEPTION: main [dupli] [duplicate]

your instantiation must be inside a method check the following and under setContentView method TextView tvnum =null; Button btnMin=null; @Override protected void onCreate(Bundle savedInstanceState) //TODO solve runtime problem(E/AndroidRuntime: FATAL EXCEPTION: main) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tvnum = (TextView) findViewById(R.id.TV_num);//creating object of TextView int id = 100;//id is first number of tv num btnMin = (Button) findViewById(R.id.btnMIN); … Read more