Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.help > #4161

need help with my code

X-Received by 10.36.66.12 with SMTP id i12mr3999973itb.2.1481559581621; Mon, 12 Dec 2016 08:19:41 -0800 (PST)
X-Received by 10.157.60.235 with SMTP id t40mr6025389otf.0.1481559581572; Mon, 12 Dec 2016 08:19:41 -0800 (PST)
Path csiph.com!weretis.net!feeder6.news.weretis.net!news.glorb.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!border1.nntp.dca1.giganews.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!p16no5753671qta.1!news-out.google.com!j8ni38943qtc.0!nntp.google.com!p16no5753668qta.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups comp.lang.java.help
Date Mon, 12 Dec 2016 08:19:41 -0800 (PST)
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=94.205.85.179; posting-account=3WhuxQoAAABPnkZ04qxVeHlWns2QpSGt
NNTP-Posting-Host 94.205.85.179
User-Agent G2/1.0
MIME-Version 1.0
Message-ID <619ae8ec-bcca-40b4-8be8-17dd0a63cb1d@googlegroups.com> (permalink)
Subject need help with my code
From Karim omar <karimyousrymohamedomar@gmail.com>
Injection-Date Mon, 12 Dec 2016 16:19:41 +0000
Content-Type text/plain; charset=UTF-8
Lines 38
X-Received-Bytes 2490
X-Received-Body-CRC 1815173099
Xref csiph.com comp.lang.java.help:4161

Show key headers only | View raw


when i use the (reply = myScanner.findInLine(".").charAt(0);) method i get the following error message 

Exception in thread "main" java.lang.NullPointerException 
        at Ifexercise1a.main(Ifexercise1a.java:18) 

and i am sure i wrote it write cause i tried copying and paste it from another prog which is working fine, i am using eclipse and i don`t know if it`s a bug in eclipse or something wrong in the class itself.

the complete code is 

import java.util.Scanner; 

public class Ifexercise1a { 

        public static void main(String[] args) { 
                 
                Scanner myScanner = new Scanner(System.in); 
                int age; 
                double price; 
                char reply; 
                 
                System.out.println("how old are you?"); 
                age = myScanner.nextInt(); 
                 
                System.out.println("you have a coupon? (Y/N)"); 
                reply = myScanner.findInLine(".").charAt(0); 
                 
                if(age <= 12 || age > 65){ 
                        price = 5.25; 
                }else{ 
                        price = 9.25; 
                } 
            if (reply == 'y' || reply == 'Y'){ 
                    price-=2.00; 
            } 
                  System.out.println("you will pay $" + price);   
                } 
         
         
} 

Back to comp.lang.java.help | Previous | NextNext in thread | Find similar


Thread

need help with my code Karim omar <karimyousrymohamedomar@gmail.com> - 2016-12-12 08:19 -0800
  Re: need help with my code Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2016-12-12 15:16 -0600

csiph-web