🔒 Closed Java patulong kung ano mali lagi kasi error

Status
Not open for further replies.

RIMURU_tempest300

Eternal Poster
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
 
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.webp
 
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

  • Screenshot_2022-04-02-08-49-44-55_a927ed2714ba3b9021f681846134c26f.webp
    Screenshot_2022-04-02-08-49-44-55_a927ed2714ba3b9021f681846134c26f.webp
    57.2 KB · Views: 38
Status
Not open for further replies.

About this Thread

  • 17
    Replies
  • 1K
    Views
  • 10
    Participants
Last reply from:
APOLLO2020

Trending Topics

Online now

Members online
347
Guests online
971
Total visitors
1,318

Forum statistics

Threads
2,272,652
Posts
28,944,393
Members
1,237,321
Latest member
agahahaha
Back
Top