What's new

Java Java patulong kung ano mali lagi kasi error

RIMURU_tempest300

Eternal Poster
Established
Joined
Jul 2, 2019
Posts
825
Solutions
1
Reaction
1,216
Points
451
Question:
"Write a program that creates an array of 10 elements size. Your program should prompt the user to input numbers in array and then display the sum of all array elements."

Screenshot_2022-03-31-22-46-02-81_a927ed2714ba3b9021f681846134c26f.jpg Screenshot_2022-03-31-22-46-06-26_a927ed2714ba3b9021f681846134c26f.jpg Screenshot_2022-03-31-22-45-12-89_a927ed2714ba3b9021f681846134c26f.jpg
 

Attachments

Last edited:
Thank me NOW not LATER

Java:
import java.util.Scanner;

public class sumOfArray {
   public static void main(String[] freeallyoucanofficial) {
      
      Scanner keyboardwarriors = new Scanner(System.in);
      int hindiAkoTigaAdd = 0;
      System.out.print("Enter how many numbers to process sum: ");
      int walangNumero = keyboardwarriors.nextInt();
      int[] hindiAkoArray = new int[walangNumero];
      System.out.println("Enter the numbers");
      for(int i = 0; i < walangNumero; i++) {
         hindiAkoArray[i] = keyboardwarriors.nextInt();
         hindiAkoTigaAdd += hindiAkoArray[i];
      }
      System.out.print("Sum of all numbers entered is: " + hindiAkoTigaAdd);
   }
}
}
 
change class ArraySum to class Main
package Java;


import java.util.Scanner;


class Main
{
public static void main(String[] args)
{
final int SIZE = 10;

int[] numbers = new int[SIZE];

Scanner console = new Scanner(System.in);
System.out.println("Enter "+ SIZE + " numbers: ");


for (int i = 0; i < SIZE; i++)
{
numbers = console.nextInt();
}
int sum = 0;

for(int i = 0; i < SIZE; i++)
{
sum += numbers;
}
System.out.println("Sum of numbers = " + sum);
}
}


ito new code ko idol ganon parin error nilang dalwa magkapariha lang ganito parin
👇
  • javac -cp . Main.java
  • java -cp . Main
Error: Could not find or load main class Main
Caused by: java.lang.NoClassDefFoundError: Java/Main (wrong name: Main)
 
package Java;


import java.util.Scanner;


class Main
{
public static void main(String[] args)
{
final int SIZE = 10;

int[] numbers = new int[SIZE];

Scanner console = new Scanner(System.in);
System.out.println("Enter "+ SIZE + " numbers: ");


for (int i = 0; i < SIZE; i++)
{
numbers = console.nextInt();
}
int sum = 0;

for(int i = 0; i < SIZE; i++)
{
sum += numbers;
}
System.out.println("Sum of numbers = " + sum);

}
}


ito new code ko idol ganon parin error nilang dalwa magkapariha lang ganito parin
👇

    • javac -cp . Main.java
    • java -cp . Main
Error: Could not find or load main class Main
Caused by: java.lang.NoClassDefFoundError: Java/Main (wrong name: Main)
working sakin, gamit ko Eclipse as compiler and IDE. try ko sa console.

working sakin, gamit ko Eclipse as compiler and IDE. try ko sa console.
hello, ganto ginawa ko ganto rin gawin mo.
rename "Main.java" to ArraySum.java

rename class Main to class ArraySum

execute this:

  • javac.exe -cp . ArraySum.java
  • java.exe -cp . ArraySum.java
1648829904771.png
 

Attachments

Last edited:
working sakin, gamit ko Eclipse as compiler and IDE. try ko sa console.


hello, ganto ginawa ko ganto rin gawin mo.
rename "Main.java" to ArraySum.java

rename class Main to class ArraySum

execute this:

  • javac.exe -cp . ArraySum.java
  • java.exe -cp . ArraySum.java
View attachment 1881628
oks na lods ty po ng marami

working sakin, gamit ko Eclipse as compiler and IDE. try ko sa console.


hello, ganto ginawa ko ganto rin gawin mo.
rename "Main.java" to ArraySum.java

rename class Main to class ArraySum

execute this:

  • javac.exe -cp . ArraySum.java
  • java.exe -cp . ArraySum.java
View attachment 1881628
Goods napo ba ito?
 

Attachments

Last edited:

Similar threads

Back
Top