[Solved] How to store each word from a scanner to an array

If I understand your question correctly, this is that I would do Scanner keyb = new Scanner(System.in); System.out.print(“Enter a sentence: “); String input = keyb.nextLine(); String[] stringArray = input.split(“,”); To see the results: for(int i=0; i < stringArray.length; i++){ System.out.println(i + “: ” + stringArray[i]); } This will work for any size sentence as long … Read more

[Solved] Java Switch not working like expected

you’re missing the break statement switch (c_a.getText()) { case “Customer”: { new LoginPage().setVisible(true); break; } case “Admin”: { new LoginPageadmin().setVisible(true); break; } default: { JOptionPane.showMessageDialog(this, “Please try again”); break; } } source: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html solved Java Switch not working like expected

[Solved] A program that continually asks for integers until a non-integer is inputted. It prints the sum of all integers inputted and the number of attempts

Try this. import java.util.Scanner; class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println (“Enter an integer to continue or a non-integer value to finish. Then press return.”); //placeholder variables that change as user inputs values int attempts = 0; String value; int total = 0; //adds the values input … Read more

[Solved] How to find the number of correct answers that user had made then convert the correct answer to percentage? [closed]

Firstly, declare some variables to work with for your test. Integer userScore=0; Integer totalScore=0; The percentage is userScore/totalScore*100. To add these up throughout the test, each of your questions should have something like this in them. if (answerIsCorrect) { userScore++; } totalScore++ To get the percentage, you just need to use your variables that have … Read more

[Solved] java servlet programming error [closed]

Need to put the servlet.jar in your CLASSPATH when you compile. The servlet.jar is part of Tomcat. You’ll probably find it in servlet/lib on version 5.5. You should know how to use -classpath option on javac.exe. You’ll probably find that there are other JARs missing as well. As you get compilation errors, keep finding the … Read more

[Solved] how to remove the space between the two triangle?

In the first for loop. Do not put i <= n but i < n and the space will dissapear. Try to figure out yourself why this is. Correctly formatted (also removed the input scanner line). public class series { public static void main (String args[]){ int n=5; if((n>=1 && n<=9)){ for(int i=0;i<n;i++){ //spacing logic … Read more

[Solved] No adapter attached; skipping layout recyclerview error

there is a blunder in MainRecyclerView‘s onCreate() recyclerView = (RecyclerView) findViewById(R.id.recycler_view); dataList = new ArrayList<>(); // your dataList is empty here… recyclerView.setAdapter(adapter); // your Adapter is null here. (not initialized) RequestJsonArray(); You need to call method which prepares your dataList before passing it to Adapter. Do call methods at proper position. @Override protected void onCreate(@Nullable … Read more

[Solved] Method Class Project

Read up on the return keyword. An example of getters and setters methods can be found at How do getters and setters work?. A setter method is a method which sets a variable in your class. Getter methods give the variable to whatever calls the method. Getters: In a main method: String s = MethodClassProject.getBrand(); … Read more