Security Software review and downloads
  • Home
  • Spyware & Spyware Remover
  • Registry & Registry Cleaner
  • Firewall
  • Hacked
  • Uninstall & Uninstaller
  • Antivirus

errors on java? fix? what mean?

September 11th, 2008 · 1 Comment

//******************************************************
// Tara D
// CS1 — 10:00 — Pgm #2
//
// Program Integers: Get five decimal numbers and convert
// to integers. Add five integers to get sum. Then take
// sum divde by five to get average.
//
//******************************************************
//
// prompt user for five decimal numbers = decNum
// print five decimal numbers = decNum
// convert decimal number to nearest integer if decNum <.5
//decNum == something
//else if decNum >.4
//decNum == something
// add five integers
// print sum and average of five integers
//
//
//******************************************************
import java.util.*;

public class MySecondJavaProgram
{
static Scanner console = new Scanner(System.in);

public static void main (String[] args)
{
//declare variables
double num1, num2, num3, num4, num5;
int sum, average;

//statements

System.out.print(”Enter a decimal number:”);
num1 = console.nextInt();
System.out.print(”Enter a decimal number:”);
num2 = console.nextInt();
System.out.print(”Enter a second decimal number:”);
num3 = console.nextInt();
System.out.print(”Enter a thrid decimal number:”);
num4 = console.nextInt();
System.out.print(”Enter a fourth decimal number:”);
num5 = console.nextInt();

System.out.println(num1, num2, num3, num4, num5);

//some statement to make decimal to nearest integer

sum = num1 + num2 + num3 + num4 + num5;
System.out.println(”The sum is ” + sum);

average =(num1 + num2 + num3 + num4 +num5) / 3;
System.out.println(”The product is ” + product + “\nThe average is ” + average);

}//static close

} // class close

—-jGRASP exec: javac -g F:\Java\Chapter 2\MySecondJavaProgram.java

MySecondJavaProgram.java:47: cannot find symbol
symbol : method println(double,double,double,double,double)
location: class java.io.PrintStream
System.out.println(num1, num2, num3, num4, num5);
^
MySecondJavaProgram.java:51: possible loss of precision
found : double
required: int
sum = num1 + num2 + num3 + num4 + num5;
^
MySecondJavaProgram.java:54: possible loss of precision
found : double
required: int
average =(num1 + num2 + num3 + num4 +num5) / 3;
^
MySecondJavaProgram.java:55: cannot find symbol
symbol : variable product
location: class MySecondJavaProgram
System.out.println(”The product is ” + product + “\nThe average is ” + average);
^
4 errors

—-jGRASP wedge2: exit code for process is 1.
—-jGRASP: operation complete.

—-jGRASP exec: java MySecondJavaProgram

Enter a decimal number:2.2
Exception in thread “main” java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:840)
at java.util.Scanner.next(Scanner.java:1461)
at java.util.Scanner.nextInt(Scanner.java:2091)
at java.util.Scanner.nextInt(Scanner.java:2050)
at MySecondJavaProgram.main(MySecondJavaProgram.java:37)

—-jGRASP wedge2: exit code for process is 1.
—-jGRASP: operation complete.

Related posts:

  • help with my java homework please errors?
  • the error i get is: IllegalFormatConversionException: f != java.lang.Integer it...
  • After installing SP3 on WIndows XP PRo, cannit get MS wireless util to work properly? HELP?
  • I cannot see the routers or my router when I try to vview wireless networks. I...
  • Why does FireFox 3 crash when I open Java Console?
  • I have FireFox 3 and whenever I click on something that needs to use Java Console (like...
  • Visual Basic-What does this code error signify, and how could it be solved?
  • I am writing a simple program for finding linear equations, i have been using sub and...
  • I can’t get my HP scanner to work on VISTA?
  • I have an HP PSC 950 and the scanner isn't working on vista. It worked before when I...
  • Guyz, kindly help me fix this error?
  • C:\j2sdk1.4.1_03\bin>javac cutedawsimam.java cutedawsimam.java:16:...
  • Is ESET NOD 32 Antivirus the reason my Java-based Instant Service email & chat occasionally freezes?
  • 1. Initially no problems with Norton. But Norton was expiring, so I decided to...
  • my current window vista ultimate pro.key cannot be found,i could not print it out.?
  • I forgot to print out my window vista product key, now i have lost my current window...
  • Printing a Java applet on a Mac using Firefox?
  • I am currently developing a web page that uses a java applet on it - printing the page is...
  • Util.DLL how can I add it to C#?
  • I am creating a program for my programming class and it requires that I use the Util.dll...

    Tags: Windows Error


    1 response so far ↓

    • 1 deonejuan // Sep 11, 2008

      When working in Terminal (or the Console), the java interpretor is, in fact, working with String. Which is good. Strings have the greatest amount of methods. Strings allow the most versitillity with conversions of Types. Consider:

      public class SumTheNumbers {

      private Scanner scanner;

      public SumTheNumbers() {
      scanner = new Scanner(System.in);
      intro();
      }
      public static void main(String[] args) {
      new SumTheNumbers();

      }

      private void intro() {

      String[] ordinals = {”first”, “second”, “third”, “fourth”, “fifth”};
      System.out.println(”Input 5 decimal numbers, such as 5.11, and”);
      System.out.println(”this program will calculate the average”);
      System.out.println(”———————”);
      float[] inputs = new float[5];
      for (int i = 0; i < inputs.length; i++) {
      System.out.println(”Input the ” + ordinals[i] + ” decimal number: “);
      inputs[i] = scanner.nextFloat();
      }
      System.out.print(”The numbers you entered are: “);

      for (int i = 0; i < inputs.length-1; i++) {
      System.out.print(inputs[i]+”, “);

      }
      // hack so there isn’t a comma on the end of the String out…
      System.out.print(inputs[inputs.length-1]);
      System.out.print(”\n”);
      System.out.println(”===========”);
      int avg = 0;
      for (int i = 0; i < inputs.length; i++) {
      String s = String.format(”%3.0f”, inputs[i]);
      s = s.trim();
      int x = Integer.parseInt( s );

      avg += x;

      }

      System.out.print(”The average is: “);

      System.out.print( avg / inputs.length );
      System.out.print(”\n”);
      }

      }
      ////////////////
      One powerful new feature of java is String.format. Look for that line above.
      String s = String.format(”%3.0f”, inputs[i]);
      % = an entity
      3.0f = make a String 3 chars wide with no decimal (it will round)
      , = start of the 2nd field String.format requires
      inputs[i] = the array of the users input values

      That makes a String. ie 3.55 turns into _ _ 4
      String.trim() turns it into 4
      Integer.parseInt(String) turns it back into a number

    Leave a Comment

    *
    To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
    Click to hear an audio file of the anti-spam word

    Tags: Email Spam Uninstall spyware Security Software Trend Micro Registry Cleaner Pc Tools Norton Nod32 Kaspersky Internet Security Hacked Firewall Computer Security Avg Avast Antivirus Ad Aware Monitoring Software Encryption Backup


    A Slow System?
    Harassed by DLL errors?
    Plagued by constant Blue Screens?
    Receiving error messages and don't know why?

     
    • Most popular Software downloads

      • Pctools
      • kaspersky
    About | Contact Us | Old Sitemap Security Software review and download . All rights reserved PoweredBy Yahoo!API.